[英]knp Paginator rendering
I'm getting an error with rendering knp paginator: 我在渲染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));
}
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
. 看起来像你的
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.