我的分页有问题。我的路线:
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>。但当我试图在url中获取页面2时,它被发送了:?第2页,但产品列表不变。
您错过了配置页面参数并在控制器中处理它:
使用以下路线:
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...
}