Pagination in CakePHP 1.3 doesn't seems to provide a way to retain
custom query string passed with the url which is an essential part for
any application.
Say if url is something like
www.example.com/post/search?section=acticle&keyword=cakephp,
the pagination links doesn't contain the query string passed. But it
can be easily achieved if we tweak pagination a bit. We can simply
pass our query string to options['url'] of Paginator with key '?'.
I used options() function to set it so that it can be used for all
links generated by Paginator
//In view file before any call to Paginator Helper
//$this->params['url'] contains all the query string with key and
value
$url_param = array_filter($this->params['url']); //strip out any
parameter which doen't have any value
unset($url_param['url']); //its not the query string so unset it,
its the path to our action with any parameter to it
$query_string = '';
//cteate the query string with key and value
foreach($url_param as $key => $val){
$query_string .= '&'.$key.'='.$val;
}
//set 'url' key which will be used by paginator helper to set our
query string in pagination
$options['url'] = array_merge($this->passedArgs, array('?'=>
$query_string));
//call the options function which will set options variable of
Paginator Helpler
$this->Paginator->options($options);
Hope this issue will be fixed in further releases.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php