-1

我的分页有问题。我的路线:

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 页时,它会发送 : ?page=2 但产品列表不会改变。

4

1 回答 1

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...
}
于 2015-03-27T13:08:28.553 回答