How to pass pagination parameters with additional

2019-04-09 20:21发布

问题:

I have a list of categories which displays the list of items under it.

Thus:

routes have:

Router::connect('/category/:slug', array('controller' => 'Product',
             'action'=>'catview', 'slug'=> '[0-9a-zA-Z]+'));
Router::connect('/category/:slug/:page', array('controller' => 'Product',
             'action'=>'catview','slug'=> '[0-9a-zA-Z]+','page'=>'[0-9]+'));

and

when I do this in results page, it just doesn't work:

<?php 
        $slug = $this->params['slug'];
        $this->Paginator->options(array('url'=> array('controller' => 'Product',
                             'action'=>'catview','slug'=> $slug)));

        echo $this->Paginator->prev('<< Show me previous', array('class'=>'prev'))
        . $this->Paginator->next('Show me more >>', array('class'=>'next')); ?>

It does not change the results, it shows the same result as it does on page 1.

Any ideas where I am going wrong?

回答1:

Thanks to AD7six for the reference.

My controller needs to have :

$this->paginate = array(
 //other stuff here
 'paramType' => 'querystring'
);

Followed by:

$this->Paginator->options(array('url'=> array('controller' => 'Product',
                                  'action'=>'catview','slug'=> $slug),
                                     'convertKeys' => array('page')));

in the view file