CakePHP Pagination Routing Issues

Within CakePHP 2 I am using pagination which works great until I see the URL which is page:2, how can I make this ?page=2 ?

The next question is that I use this code for my controller which powers /domain.com/offers/top, /domain.com/offers/newest, /domain.com/offers/popular and then the categories like /domain.com/offers/tv-and-video. The thing is when it is paginated for /domain.com/offers/top instead of being /offers/top/page:2 it goes to /offers/bycategory/top/page:2.

 public function bycategory($slug = null)
{

    $userId = $this->Session->read("UserAuth.User.id");
    if ($slug == 'top') {
        //Get the top rated offers
        $this->paginate = array(
            'limit' => 15,
            'order' => array(
                'Offer.vote' => 'desc'
            )
        );
    } elseif ($slug == 'newest') {
        //Get the latest offers
        $this->paginate = array(

            'limit' => 15,
            'order' => array(
                'Offer.created' => 'desc'
            )
        );
    } elseif ($slug == 'popular') {
        //Get the most talked about offers
    } else {

        //This is the categories, so just get the category slug.
        $this->paginate = array(
            'conditions' => array('Category.slug =' => $slug),
            'limit' => 15,
            'order' => array(
                'Offer.created' => 'desc'
            )
        );


    }


    $offers = $this->paginate('Offer');

    // pass the value to our view.ctp
    $this->set('offers', $offers);
    $this->set('userId', $userId);

    $this->render('/Offers/index');


}

This is my custom route:

Router::connect(
'/offers/:catslug',
array('controller' => 'offers', 'action' => 'bycategory'),
array(

    'pass' => array('catslug')

));

Answers


how can I make this ?page=2 ?

By setting the paramType option in paginator component options as mentioned in manual.

You second issue looks like reverse routing issue. Have you setup any custom routes?


Need Your Help

how to clear the items of a listview control and datapager

c# asp.net listview data-binding

I have a ListView control. I am displaying the data but once the user clicks the clear button

How to match data values with array values

php arrays match explode array-intersect

So i'm trying to match the values from the database with values from an array.