【发布时间】:2013-02-08 10:22:31
【问题描述】:
我有一个方法,它执行搜索并将结果发送到它的视图。搜索结果仅在分页结果的第一页上可用。随后的分页页面没有数据并且有关于无效索引/变量的警告/错误:
控制器
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']); ?> </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>
如何让第二个及后续页面显示搜索页面的结果?
【问题讨论】:
-
能否请您展示整个控制器?也许是相应的视图......我的猜测是你通过 POST 发送信息并且你没有将 POST 转换为 GET
-
最好不要重新发明轮子。搜索插件很复杂,比大多数自编码解决方案做得更好:github.com/cakedc/search
-
为控制器和视图添加了代码。
-
@AD7six :我查看了您提供的链接。我有一个城市下拉列表(jquery ajax),它取决于状态信息。如果我按照该链接中的建议将表单转换为 GET,则此 ajax 部分会中断。
标签: cakephp cakephp-2.2