I have a controller and view.
in the view it will displays all the records frm the database.
also there is a searchby form in the top of that view page.
if we specify a search term, and submit the form , the view will only displays the records resulting from that search.
the results are paginated.
but the problem is when i perform a search and click on the next page of the results , it will shows all the results .. here is my code.
View page
index.ctp
echo $form->create('Apartment', array('action'=>'index'));
echo form->input('searchBy',array('type'=>'select','options'=>array('Id'=>'Id','User'=>'User','time'=>'Updated time')));
echo $form->input('query', array('type'=>'text', 'label'=>'Search Term'));
echo $form->end(array('name'=>'submit', 'label'=>'Search'));
<th class="actions"><?php __('');?></th>
<th><?php echo $paginator->sort('id');?></th>
<th><?php echo $paginator->sort('Headline');?></th>
<th><?php echo $paginator->sort('Campaign','Campaign.Name');?></th>
<th><?php echo $paginator->sort('User', 'User.name');?></th>
<th><?php echo $paginator->sort('modified');?></th>
<th><?php echo $paginator->sort('status');?></th>
<th class="actions"><?php __('Actions');?></th>
Controller index function
if (!empty($this->data)) {
// Search
switch($this->data['Apartment']['searchBy'])
{
case 'Id':
$apartments = $this->paginate(NULL, array('Apartment.id' => $this->data['Apartment']['query']));
break;
case 'User':
$apartments = $this->paginate(NULL, array("User.name Like '%".$this->data['Apartment']['query']."%'"));
break
case 'time':
$apartments = $this->paginate(NULL, array("Apartment.modified Like '%".$this->data['Apartment']['query']."%'"));
break;
}
}
else {
$apartments = $this->paginate();
}