Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

In my controller :

    $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
    ));

I view :

<div class="navigation">
     {{ knp_pagination_render(pagination) }}
</div>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
303 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

use this route:

show_product_category:
    path:     /{id}/{name}/{page}
    defaults:
        _controller: ShopDesktopBundle:Category:showCategory
        page: 1
    requirements:
        id:  d+
        page: d+
    methods: [GET]

and in controller:

public function showCategoryAction($id, $name, $page)
{
    //your code.....
    $pagination = $paginator->paginate(
    $aProducts,
    $page,
    3
    );
    // your code...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...