Symfony 如何在一个getRepository中获取多个实体的存储库

Symfony 如何在一个getRepository中获取多个实体的存储库,symfony,repository,entity,Symfony,Repository,Entity,我已经试过了,但它不起作用,只执行第一个实体 $resultat = $con->getRepository("PFESiivtBundle:Categorie","PFESiivtBundle:Evenement", "PFESiivtBundle:Projet")->findBy(array('idPublication' =>$respub),array('id'=>'DESC') ); 您的方法行不通,您应该创建一个存储库,然后加入您的表 class Categ

我已经试过了,但它不起作用,只执行第一个实体

$resultat = $con->getRepository("PFESiivtBundle:Categorie","PFESiivtBundle:Evenement",
"PFESiivtBundle:Projet")->findBy(array('idPublication' =>$respub),array('id'=>'DESC') );

您的方法行不通,您应该创建一个
存储库
,然后加入您的表

class CategorieRepository extends EntityRepository
{
   public function getCategorieRelatedDataByIdAndIdPublication($idPublication)
   {
       $qb = $this->entityManager->createQueryBuilder();
       $qb->select('c', 'e', 'p')
        ->from('PFESiivtBundle:Categorie', 'c')
        ->leftJoin('c.eveniment', 'e')
        ->leftJoin('c.project', 'p')
        ->where('c.id = :id')
        ->andWhere('c.idPublication = :id_publication')
        ->setParameter('id_publication', $idPublication)

        return $qb->getQuery()->getResult();
   }
} 
连接将取决于您的映射,没有映射结构,我无法为您提供正确的代码

然后在
控制器中
使用如下:


$resultat=$con->getRepository(“pfesivtbundle:Categorie”)->getcategoriateddatabyandidpublication($idPublication)

您不能,您应该在实体之间使用join close