Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在symfony中由用户_id加入_Php_Symfony_Doctrine Orm - Fatal编程技术网

Php 在symfony中由用户_id加入

Php 在symfony中由用户_id加入,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,如何通过symfony两个表格选择数据。例如,有一个帖子表,它是一个字段user_id(创建帖子的用户),我会选择所有帖子并传递给模板。模板必须显示表users中的用户数据(对于用户id上的每个帖子),因为可以这样做吗 我读了文档,但没有真正理解 我现在的问题是: public function indexAction() { $posts = $this->getDoctrine() ->getReposit

如何通过symfony两个表格选择数据。例如,有一个帖子表,它是一个字段user_id(创建帖子的用户),我会选择所有帖子并传递给模板。模板必须显示表users中的用户数据(对于用户id上的每个帖子),因为可以这样做吗

我读了文档,但没有真正理解

我现在的问题是:

   public function indexAction()
    {
        $posts = $this->getDoctrine()
                      ->getRepository('AcmePostBundle:Post');

        $queryPosts = $posts->createQueryBuilder('p')
                       ->orderBy('p.id', 'DESC')
                       ->getQuery();

        return new Response(var_dump($queryPosts->getResult()));
   }

我想按用户id获取表“users”的列
路径

您是否在模板中尝试执行以下操作: (假设您从我们的控制器返回帖子)

你应该在你的var_转储中看到这一点


在你的存储库帖子中试试这个

public function myInnerJoin()
{

       $qb = $this->createQueryBuilder('f') 
            ->select('f','g')
            ->innerJoin('f.user', 'g'); 

       return $qb->getQuery()->getArrayResult();
}
和在控制器中

$repository = $this->getDoctrine()->getManager()->getRepository('AcmeBundle:..');
$result = $repository->myInnerJoin(); 

否,缺少$POST的用户。我没有加入,我不知道怎么做我添加了一个如何加入的例子。您也可以根据需要加入leftjoin
$repository = $this->getDoctrine()->getManager()->getRepository('AcmeBundle:..');
$result = $repository->myInnerJoin();