12

When using the paginator helper in cakephp views, it doesnt remember parts of the url that are custom for my useage.

For example:

http://example.org/users/index/moderators/page:2/sort:name/dir:asc

here moderators is a parameter that helps me filter by that type. But pressing a paginator link will not include this link.

Alexander Morland
  • 6,356
  • 7
  • 32
  • 51

6 Answers6

11

The secret is adding this line to your view:

$paginator->options(array('url'=>$this->passedArgs));

(I created this question and answer because it is a much asked question and I keep having to dig out the answer since i cant remember it.)

Alexander Morland
  • 6,356
  • 7
  • 32
  • 51
4

To add to Alexander Morland's answer above, it's worth remembering that the syntax has changed in CakePHP 1.3 and is now:

$this->Paginator->options(array('url' => $this->passedArgs));

This is described further in the pagination in views section of the CakePHP book.

Loftx
  • 1,760
  • 4
  • 29
  • 50
0

$this->passedArgs is the preferred way to do this from the view.

Martz
  • 428
  • 3
  • 5
0

You saved me! This helped me a lot, Thanks.

I needed a way to pass the parameters I originally sent via post ($this->data) to the paging component, so my custom query would continue to use them.

Here is what I did:

on my view I put

$paginator->options(array('url'=>$this->data['Transaction']));

before the $paginator->prev('<< Previous ' stuff.

Doing this made the next link on the paginator like " .../page:1/start_date:2000-01-01%2000:00:00/end_date:3000-01-01%2023:59:59/payments_recieved:1"

Then on my controller I just had to get the parameters and put them in the $this->data so my function would continue as usual:

foreach($this->params['named'] as $k=>$v)
{
    /*
     * set data as is normally expected
     */
    $this->data['Transaction'][$k] = $v;
}

And that's it. Paging works with my custom query. :)

0

The options here are a good lead ... You can also check for more info on cakePHP pagination at cakephp.org/view/166/Pagination-in-Views

-1

With that param 'url' you can only put your preferred string before the string pagination in url..

if I use this tecnique:

$urlpagin = '?my_get1=1&my_get2=2';
$paginator->options = array('url'=>$urlpagin);

I only obtain:

url/controller/action/?my_get1=1&my_get2=2/sort:.../...

and Cake lost my get params

Have you an alternative tecnique?

  • dont pass parameters as $_GET[]... your url should be something like... url/controller/action/par1:val1/par2:val2 – Yashvit Feb 16 '10 at 23:39