I have a controller and view. In the view it will displays all the records from the database. Also there is a search by 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.
İşte benim kodudur.
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'));
<?php echo $this->element('pagination'); ?>
<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>
Kontrolör indeks fonksiyonu
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();
}