Reputation: 35
I'm getting an error with rendering knp paginator:
An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Argument 2 passed to Knp\Bundle\PaginatorBundle\Twig\Extension\PaginationExtension::render() must be an instance of Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination, array given, called in C:\wamp\www\TunisiaMall\app\cache\dev\twig\7b\87\136d965ad591aa95bee5c88d324ab4fe15f38a8af882bbdb9ef9f4ac9320.php on line 78 and defined in C:\wamp\www\TunisiaMall\vendor\knplabs\knp-paginator-bundle\Twig\Extension\PaginationExtension.php line 43") in TMallClientBundle:Default:detailBoutique.html.twig at line 29.
here is code for the controller:
public function boutiqueDetailAction(){
$em = $this->getDoctrine()->getManager();
$boutiq = $em->getRepository("TMallEntityBundle:boutique")->findAll();
$boutique = $this->get('knp_paginator')->paginate(
$boutiq,
$this->get('request')->query->get('page', 1)/*page number*/,
2/*limit per page*/
);
return $this->render("TMallClientBundle:Default:detailBoutique.html.twig",array("boutiques"=>$boutiq));
}
Upvotes: 1
Views: 5405
Reputation: 2654
Controller:
use Symfony\Component\HttpFoundation\Request;
..................................................................
public function boutiqueDetailAction(Request $request) {
$em = $this->getDoctrine()->getManager();
//findAll is very slow
$boutiq = $em->getRepository("TMallEntityBundle:boutique")->findAll();
//I suggest use queryBuilder
$boutiq = $em->getRepository("TMallEntityBundle:boutique")>createQueryBuilder('s')->getQuery();
$boutique = $this->get('knp_paginator')->paginate(
$boutiq,
$request->query->get('page', 1)/*page number*/,
10 /*limit per page*/
);
return $this->render("TMallClientBundle:Default:detailBoutique.html.twig",array("boutiques"=>$boutiq));
}
...........................................................................
Looks like your View
.
<table>
<tr>
<th>Id'</th>
<th>Title'</th>
<th>Date</th>
</tr>
{% for article in pagination %}
<tr>
<td>{{ article.id }}</td>
<td>{{ article.title }}</td>
<td>{{ article.date | date('Y-m-d') }}</td>
</tr>
{% endfor %}
</table>
<div class="navigation">
{{ knp_pagination_render(pagination) }}
</div>
Upvotes: 3