I have a method, that performs a search and sends the results to its view. The search results are available only on the first page of the pagination results. The subsequent paginated pages do not have data and have warnings/errors about invalid index/variables:
Controller
public function show_list ()
{
$i_state_id = $this->data['Contact']['state_id'];
$str_city = $this->data['Contact']['city'];
$this->Contact->recursive = -1;
$this->paginate = array (
'conditions' => array ('Contact.state_id' => $i_state_id, 'Contact.city'=> $str_city),
'fields' => array('Contact.id', 'Contact.name', 'Contact.mobile1', 'Contact.city'),
'order' => array ('Contact.id' => 'desc'),
'limit' => 2,
'recursive' => -1
);
$contacts = $this->paginate('Contact');
$this->set ('contacts', $contacts);
$this->set('state_id', $i_state_id);
$this->set('city', $str_city);
}
View (show_list.ctp)
<div class="contacts index">
<h2><?php echo __('Select the list of contacts, that you wish to move.'); ?></h2>
<?php echo $this->Form->create('Contact',array('action'=>'add_contacts_to_user'));?>
<table cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Form->checkbox('all', array('label'=>"Select All", "onclick" =>"toggleChecked(this.checked)" )); ?></th>
<th><?php echo $this->Paginator->sort('name'); ?></th>
<th><?php echo $this->Paginator->sort('Contact Info'); ?></th>
<th><?php echo $this->Paginator->sort('city'); ?></th>
</tr>
<?php
foreach ($contacts as $contact): ?>
<tr>
<td><?php echo h($contact['Contact']['id']); ?> </td>
<td><?php echo $this->Form->checkbox('Contact.id.'.$contact['Contact']['id'], array('class' => 'checkbox', 'value'=> $contact['Contact']['id'],'hiddenField' => false)); ?></td>
<td><?php echo h($contact['Contact']['name']); ?> </td>
<td><?php echo h($contact['Contact']['mobile1']); ?> </td>
<td><?php echo h($contact['Contact']['city']); ?> </td>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php
echo $this->Form->end("Move to Address Book");
?>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?> </p>
<div class="paging">
<?php
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'));
?>
</div>
</div>
How do I get the second and subsequent pages to show the results of the search pages?