我的paginate有问题。我的路线:
show_product_category:
path: /{id}/{name}
defaults: { _controller: ShopDesktopBundle:Category:showCategory}
requirements:
id: \d+
_method: GET
在我的控制器中:
$aProducts = $repositoryProduct->getProductsOrderByDateDesc($id);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$aProducts,
$this->get('request')->query->get('page', 1),
3
);
return $this->render('ShopDesktopBundle:Category:category.html.twig',array(
'pagination' => $pagination
));
我认为:
<div class="navigation">
{{ knp_pagination_render(pagination) }}
</div>
正常计算产品数量,在视图中我看到:1 2 3&gt;。 但当我试图在网址中获取第2页时,它会发送:?page = 2但产品列表不会更改。
答案 0 :(得分:0)
您错过了配置页面参数并在控制器中处理它:
使用这条路线:
show_product_category:
path: /{id}/{name}/{page}
defaults:
_controller: ShopDesktopBundle:Category:showCategory
page: 1
requirements:
id: \d+
page: \d+
methods: [GET]
并在控制器中:
public function showCategoryAction($id, $name, $page)
{
//your code.....
$pagination = $paginator->paginate(
$aProducts,
$page,
3
);
// your code...
}