Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakePHP paginate with post data without sessions, serialization or post to get

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

like image 724
openprojdevel Avatar asked May 28 '10 07:05

openprojdevel


2 Answers

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.

  1. Search must be done using GET method.

  2. 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
like image 76
Your Common Sense Avatar answered Sep 25 '22 00:09

Your Common Sense


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));
like image 44
BenJsno Avatar answered Sep 23 '22 00:09

BenJsno