我正在设置 knp 分页器,我的作曲家设置为 "knplabs/knp-paginator-bundle": "2.3.*" 但是它不适用于 Query 对象。
这是我的查询:
public function getCommentariesByUser(User $user) {
$qb = $this->createQueryBuilder('c');
$qb->innerJoin('c.item', 'i');
$qb->andWhere($qb->expr()->eq('i.user', ':user'))
->setParameter(':user', $user);
$qb->andWhere($qb->expr()->neq('c.user', ':user1'))
->setParameter(':user1', $user);
return $qb->getQuery();
}
我如何在我的行动中称呼它:
public function commentariesAction($page) {
$user = $this->getUser();
$commentaryRepository = $this->getDoctrine()->getRepository('My\MyBundle\Entity\Commentary');
$query = $commentaryRepository->getCommentariesByUser($user);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query,
$page/*page number*/,
15/*limit per page*/
);
return array('pagination' => $pagination);
}
它根本不显示结果,但是如果我把 $query->execute() 它工作。怎么了?