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

匿名 (未验证) 提交于 2019-12-03 02:51:02

问题:

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.

回答1:

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.



回答2:

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



回答3:

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



回答4:

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



回答5:

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



回答6:

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?



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!