【发布时间】:2014-08-13 15:14:00
【问题描述】:
所以,我正在开发一个新闻门户。我正在使用 KNP Paginator,但出现错误: 无法统计选择两个 FROM 组件的查询,无法区分
现在,我的源代码:
#block of code from controller
$rep = $this->getDoctrine()->getRepository('NickCoreBundle:News');
$user = $this->get('security.context')->getToken()->getUser();
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$rep->getNewsFeedQuery($user->getId()),
$page,
10
);
来自我的存储库:
public function getNewsFeedQuery($userid)
{
$userid = intval($userid);
return $this->getEntityManager()->createQueryBuilder()
->select('n')
->from('NickCoreBundle:News', 'n')
->innerJoin('NickCoreBundle:Subscriptions', 's', 'WITH', 's.user = :userid AND n.source = s.source')
->orderBy("n.date","DESC")
->setParameter('userid', $userid)->getQuery();
}
如何解决它:) ?试图从查询中获取结果,在 ArrayCollection 中,它可以工作(部分,不按日期排序,我认为这种方法使用了很多时间)
【问题讨论】:
-
你不应该按
news.id分组吗? (例如->groupBy('n.id'))?
标签: php mysql symfony pagination knppaginator