I have created a small search and filter form with a POST action in controller/index, which POSTs to itself the conditions and fields to paginate ($this->paginate($conditions)
).
That is good for the first page, however on the subsequent pages the filter conditions are lost. Pagination passedArgs
supports GET variables well.
Are there an un-complex ways to pass the POST conditions to the other paginated pages?
The method I have looked at is to pass the $conditions
via the session, which isn't without complexity of assigning the session and unsetting the session on submitting the form again (more refinements to the filter criteria by the user).
The other method is passing the $conditions
as serialized string with url_encode
as a GET parameter.
Is there a good 'cake' way to do this more like passedArgs
. Sessions and url_encode
do not look like cake style.
Thanks
Is there an un complex way to pass the post conditions to the other paginated pages?
Nope.
Is there an good cake way to do this more like passArgs, sessions and url encode do not look like cake style.
There is only one way, no matter, cake or not cake.
Search must be done using GET method.
Parameters being passed via QUERY STRING.
So, make your search form with method="GET" and then use http_build_query() to assemble a query string and use it to make links to other pages.
Being a little curious, you can see an example right here on SO:
http://stackoverflow.com/questions/tagged?tagnames=php&page=5&sort=newest&pagesize=50
You can use passedArgs.
in the method controller :
if ( empty($this->passedArgs['search']) ){
$this->passedArgs['search'] = $this->data['YourModel']['search'];
}
if ( empty($this->data) ){
$this->data['YourModel']['search'] = $this->passedArgs['search'];
}
in your view :
$this->Paginator->options(array('url' => $this->passedArgs));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With