I'm trying to use the KnpPaginatorBundle for Symfony2 that you can find here.
When I try to do the following:
$em = $this->getDoctrine()->getManager();
$query = $em->getRepository('VolleyScoutBundle:Users')->findAll();
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1)/*page number*/,
10/*limit per page*/
);
// parameters to template
return $this->render('VolleyScoutBundle:Admin:accounts.html.twig', array('pagination' => $pagination));
I always get an error like this: One of listeners must count and slice given target
. When I dump the query before the pagination I just get an array with Entity objects from user..
What am I doing wrong?
I was getting the same error.
It didn't seem to be working for me unless I used the LTS version of Symfony2:
However I also used an EventListener which might have helped:
https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/custom_pagination_subscribers.md