I am settting up knp paginator, my composer is set to "knplabs/knp-paginator-bundle": "2.3.*" however It is not working for Query object.
Here is my 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();
}
How I am calling it in my action:
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);
}
It simply doesn't show results, however If I put $query->execute() It works. What's wrong?
Currently this is possible to use next combination of paginator packages for code above to work:
"knplabs/knp-components": "1.2.1",
"knplabs/knp-paginator-bundle": "~2.3"