Cakephp URL while Paginating with search

2019-09-06 11:45发布

问题:

I've a simple cakephp app with search and pagination. I'm using GET as type for forms.

When I click search with desired filters, paginated results are shown. I get desired results when I move across pages (with URL being modified with desired index of page number and filtered parameters).

Say I'm on page:4 of paginated search results. Now when I modify some search filter and hit search button again with page:4 shown, if results have less records (say that can be accommodated on one page), I get error - unable to find xxxxxx on server. (....../page:4/.... doesn't exist)..

Please help!

回答1:

when you press search usually you want to reset all or same of the paginator parameters

I guess that in your view you just did

echo $this->Form->create('Model');

in this way cake assume that the action of the form is the url of the page you are in

but you can set the url of the form this way

echo $this->Form->create('Model', array('url' => array('page' => 1));


回答2:

Resolved it as follows

$url = array('controller' => 'cc', 'action' => 'aa') + $this->request->params['pass'];
echo $this->Form->create(null, array('type' => 'get','url' => $url));

Thanks for your help.