I have an action from a controller that provides a result variable via $this->set('found_products', $data);
. The view page products.ctp
is divided into two sections:
On top, a form where a user enters a string to search $found_products
is set for the view.
Below it, paginated results that is displayed only if $found_products
is set. i.e. if (isset($found_products))
is true.
When if (isset($found_products))
is true, I get the first page displayed below the form with the search string already in the text box. The URL for this is myapp/controller/products
.
The problem occurs when I move into the next pages. The URL becomes myapp/controller/action/products:2
and none of the variables used under myapp/controller/products
exist. It looks like moving onto a new page clears all variables.. Below is the code I'm using for paging, and I have no reroute rules written for this. How do I solve this issue?
<div class="paging">
<?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
<?php echo $this->Paginator->numbers();?>
<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
</div>
I've tried to work around this using $_SESSION in the action (products
) and setting this for the view, but when I did this, `$this->Paginator' no longer worked.
You can use the $this->Paginator->options to preserve the passed arguments in the pagination links. Try this code
<div class="paging">
<?php $this->Paginator->options(array('url' => $this->passedArgs)); ?>
<?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
<?php echo $this->Paginator->numbers();?>
<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
</div>