本文主要介紹了Symfony2聯合查詢實作方法,結合實例形式簡單分析了Symfony2聯合查詢的具體步驟與實作技巧。需要的朋友可以參考下,希望對大家有幫助。
1.yml檔案
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.查詢程式碼:
$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();
#相關推薦:
詳解Symfony在模板和行為中取得request參數的方法
以上是詳解Symfony2實現聯合查詢的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!