Reputation: 4084
Cakephp 2.0 Pagination issue. How to pass arguments in pagination link?
I passed the arguments like
$this->Paginator->options(array('url' => $this->request->query));
but after 2 nd page its not working .
On first page submitted values are coming in $this->request->query
but from second page
its coming in $this->params->named
but it needs to come in $this->request->query
My Pagination part from view file:
<div class="paging">
<?php
$this->Paginator->options(array('url' => $this->request->query));
echo $this -> Paginator -> prev('< ' . __('Previous'), array(), null, array('class' => 'prev disabled'));
echo $this -> Paginator -> numbers(array('separator' => ''));
echo $this -> Paginator -> next(__('Next') . ' >', array(), null, array('class' => 'next disabled'));
?>
while printing params on first page :
[query] => Array
(
[first_name] =>
[username] => an
[email] =>
[dob] => Array
(
[year] =>
[month] =>
[day] =>
)
)
while printing params on second page :
[named] => Array
(
[first_name] =>
[username] => an
[email] =>
[dob%5Byear%5D] =>
[dob%5Bmonth%5D] =>
[dob%5Bday%5D] =>
)
[query] => Array
(
[/admin/users/index/first_name:/username:an/email:/dob] => Array
(
[year] =>
)
)
</div>
Upvotes: 3
Views: 5613
Reputation: 4084
I added the following code in View file and now every thing is working fine. in all pages param values are coming in request->query
$url = $this->params['url'];
unset($url['url']);
if(isset($this->request->data) && !empty($this->request->data)) {
foreach($this->request->data[$model_name] as $key=>$value)
$url[$key] = $value;
}
$get_var = http_build_query($url);
$arg1 = array();
$arg2 = array();
//take the named url
if(!empty($this->params['named']))
$arg1 = $this->params['named'];
//take the pass arguments
if(!empty($this->params['pass']))
$arg2 = $this->params['pass'];
//merge named and pass
$args = array_merge($arg1,$arg2);
//add get variables
$args["?"] = $get_var;
$this->Paginator->options(array('url' => $args));
And in Controller action method I added the following
$args = $this->params['url'];
unset($args['url']);
if(isset($args['submit']))
unset($args['submit']);
if(!empty($this->request->data)){
foreach($this->data['User'] as $key=>$value)
$args[$key] = $value;
}else{
foreach($args as $key=>$value)
$this->request->data['User'][$key] = $value;
}
Upvotes: 1
Reputation: 8528
According the the docs, the url
option of PaginatorHelper::options
has the following 3 sub-options:
Your CakeRequest::query
does not have these keys defined. I'm not sure why it would work for the first page and not the others, but your current structure is incorrect.
If you're worried about passing the querystring values to the next page, keep this in mind:
By default PaginatorHelper will merge in all of the current pass and named parameters. So you don’t have to do that in each view file.
Upvotes: 1