0

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?

dextervip
  • 4,999
  • 16
  • 65
  • 93
  • Are you returning $pagination for testing purposes? I'm new with KnpPaginatorBundle, but I pass it through to the view using: `return $this->render('MyBundle::myTemplate.html.twig', array('pagination'=>$pagination));` You then use something like `{% for item in pagination %}` to access the items. – caponica Jun 27 '13 at 16:35
  • Also, does it work if you use the QueryBuilder instead of the Query? i.e. `return $qb` instead of `return $qb->getQuery()` from `getCommentariesByUser()` – caponica Jun 27 '13 at 16:38

1 Answers1

0

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"
WayFarer
  • 1,040
  • 11
  • 19