在KnpPager中分页不起作用 [英] Paginate in KnpPager not work

查看:109
本文介绍了在KnpPager中分页不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a problem with my paginate. My route :

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,但产品列表没有更改.

It's calculate normal the count of products and in view I see : 1 2 3 >. But when I tried to get the page 2 in url it's send : ?page=2 but the list of products not change.

推荐答案

您错过了配置页面参数并在控制器中对其进行处理的步骤:

you missed to configure the page parameter and process it in your controller:

使用此路线:

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...
}

这篇关于在KnpPager中分页不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆