Why doesnt paginator remember my custom parameters when I go to page 2?
Asked Answered
M

6

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.

Monacid answered 29/9, 2008 at 8:51 Comment(0)
W
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.

Whiteley answered 19/5, 2011 at 9:19 Comment(0)
M
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.)

Monacid answered 29/9, 2008 at 8:52 Comment(0)
W
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.

Whiteley answered 19/5, 2011 at 9:19 Comment(0)
P
0

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

Perish answered 9/12, 2008 at 17:3 Comment(0)
H
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. :)

Henleigh answered 28/12, 2008 at 21:38 Comment(0)
T
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

Taiwan answered 1/6, 2009 at 17:52 Comment(0)
H
-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?

Hamilton answered 21/6, 2009 at 16:42 Comment(1)
dont pass parameters as $_GET[]... your url should be something like... url/controller/action/par1:val1/par2:val2Nealneala

© 2022 - 2024 — McMap. All rights reserved.