I have the Problem, that the knp paginator only works like this:
$em = $this->get('doctrine.orm.entity_manager');
$dql = "SELECT a FROM MainArtBundle:Art a";
$query = $em->createQuery($dql);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1) /*page number*/,
8 /*limit per page*/
);
But not in this way:
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('MainArtBundle:Art')->findAll();
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$entities,
$this->get('request')->query->get('page', 1) /*page number*/,
/*limit per page*/
);
Why is it like this? I don't understand.
Here´s my twig call :
<li>{{ knp_pagination_sortable(paginator, 'Oldest', 'a.id', {'direction': 'desc'}) }}</li>
Greetings Michael
findAll()
is compatible with Knp_paginator, you just have to give it to your paginator :
$query = $em->getRepository('Acme\FOOBundle\Entity\BAR')->findAll();
$paginator = $this->get('knp_paginator');
requests = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1),
5
);