-1

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']); ?>&nbsp;</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']); ?>&nbsp;</td>
                <td><?php echo h($contact['Contact']['mobile1']); ?>&nbsp;</td>
        <td><?php echo h($contact['Contact']['city']); ?>&nbsp;</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?

Ajay K
  • 354
  • 1
  • 4
  • 14
  • 1
    could you please show the entire controller? and maybe the corresponding view... My guess is that you're sending the info by POST and you're not transforming the POST into GET – pleasedontbelong Feb 08 '13 at 10:30
  • 1
    It might also be a good idea to not reinvent the wheel. The search plugin is sophisticated and does the job better than most self-coded solutions: https://github.com/cakedc/search – mark Feb 08 '13 at 10:34
  • Added code for the controller and the view. – Ajay K Feb 08 '13 at 16:49
  • possible duplicate of [pagination with search results in cakephp](http://stackoverflow.com/questions/13255548/pagination-with-search-results-in-cakephp) – AD7six Feb 08 '13 at 16:51
  • @AD7six : I looked at the link you provided. I have a city dropdown (jquery ajax), that is dependent on state info. This ajax portion breaks, if I convert the form to a GET, as suggested in that link. – Ajay K Feb 08 '13 at 18:21
  • -1 then. This is such a common/old problem, I simply picked the first duplicate. There are many ways to solve this, and if your js breaks - _change the js_. – AD7six Feb 08 '13 at 19:25

1 Answers1

1

You should pass your search parameters using GET Method.

For Example:

localhost/controller/action?state_id=0

    or

localhost/controller/action/state_id:10

Then your pagination will work according to search parameters.

Vijay Choudhary
  • 848
  • 1
  • 9
  • 18