We can do this with a patch.
In views:
create a search form:
$this->Form->create('Search', array('url' => array('controller' => 'controller', 'action' => 'index', substr(time(), 2,rand(1, 7) ))) );
Note. A random number added at the end of the form action. This will tell us when to clear the session.
in the controller:
public function index( $search = null) { $conditions = array(1 => 1); if( !empty($this->data['Search']['keyword']) && $search) { $conditions = array('Model.field like' => $this->data['Search']['keyword'] . '%'); // store search array in session $this->Session->write('conditions', $this->data['Search']); } if ($search) { $this->request->data['Search'] = $this->Session->read('conditions'); $conditions = array('Model.field like' => $this->data['Search']['keyword'] . '%'); } else { $conditions = array(1 => 1); $this->Session->delete('conditions'); } $this->paginate= array('limit'=> 10, 'conditions' => $conditions); $lists = $this->Paginate('Model'); }
I hope you understand the logic.
source share