This article mainly introduces the implementation of Symfony2 joint query, and analyzes the specific steps and implementation skills of Symfony2 joint query in combination with the instance form, for more information about how to implement the Symfony2 joint query, see the example in this article. We will share this with you for your reference. The details are as follows:
1. yml File
Acme\MspadminBundle\Entity\MspArticle: type: entity table: msp_article manyToOne: Channel: targetEntity: MspChannel inversedBy: Articles joinColumn: name: channel_id referencedColumnName: channel_id User: targetEntity: MspUser inversedBy: Userone joinColumn: name: user_id referencedColumnName: user_id
Acme\MspadminBundle\Entity\MspChannel: type: entity table: msp_channel oneToMany: Articles: targetEntity: MspArticle mappedBy: Channel
Acme\MspadminBundle\Entity\MspUser: type: entity table: msp_user oneToMany: Userone: targetEntity: MspArticle mappedBy: User
2. query code:
$sql="SELECT a.id,a.checkStatus,a.title,a.releaseSysDate, a.visitTotal,u.userName ,n.name FROM AcmeMspadminBundle:MspArticle a JOIN a.User u JOIN a.Channel n";$query = $emt->createQuery($sql." Where a.checkStatus = 0 ");$mspArtile = $query->getResult();
I hope this article will help you design PHP programs based on the Symfony framework.