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

how can i get repository of many entities in one getRepository

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

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

您的方法行不通,您应该创建一个 Repository 然后加入您的表格,

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();
   }
} 

连接将取决于你的映射,没有映射结构我不能给你正确的代码。

然后在Controller你将使用如下:

$resultat = $con->getRepository("PFESiivtBundle:Categorie")-> getCategorieRelatedDataByIdAndIdPublication($idPublication);