欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Symfony2联合查询实现方法

程序员文章站 2023-12-14 18:55:28
本文实例讲述了symfony2联合查询实现方法。分享给大家供大家参考,具体如下: 1.yml文件 acme\mspadminbundle\entity\mspa...

本文实例讲述了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框架的php程序设计有所帮助。

上一篇:

下一篇: