views:

1350

answers:

7

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.

+8  A: 

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
A: 

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

Martz
A: 

Hey!

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. :)

A: 

Hi,

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

A: 

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?

please dont post a question as an answer..
Alexander Morland
dont pass parameters as $_GET[]... your url should be something like...url/controller/action/par1:val1/par2:val2
Yash
A: 

THANKS for this post!

Juri
A: 

Thanks, works perfectly :)

Jan Huntjens