-1

我有一个方法,它执行搜索并将结果发送到它的视图。搜索结果仅在分页结果的第一页上可用。随后的分页页面没有数据,并且有关于无效索引/变量的警告/错误:

控制器

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);
}

查看 (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>

如何让第二个和后续页面显示搜索页面的结果?

4

1 回答 1

1

您应该使用 GET 方法传递您的搜索参数。

例如:

localhost/controller/action?state_id=0

    or

localhost/controller/action/state_id:10

然后您的分页将根据搜索参数工作。

于 2013-02-08T11:08:26.247 回答