蛋糕PHP分页问题
问题描述:
我有一个控制器和视图。 在视图中它将显示数据库中的所有记录。 此外,在该视图页面的顶部还有一个窗体搜索。 如果我们指定一个搜索词并提交表单,则该视图将仅显示该搜索产生的记录。 结果分页。 但问题是当我执行搜索并单击结果的下一页时,它会显示所有结果。蛋糕PHP分页问题
这是我的代码。
查看页面 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>
控制器指数函数
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();
}
答
您查看样品看起来不完整的,但我会首先检查,以确保你包括prev
和next
方法从视图中的PaginationHelper中查看,以确保搜索条件得到传播。
<?php
echo $paginator->prev('« Previous ', null, null, array('class' => 'disabled'));
echo $paginator->next(' Next »', null, null, array('class' => 'disabled'));
?>
此外,我希望你正在清理你传递给paginator的搜索参数。
我已经在其中添加了分页元素。 element('pagination'); ?> – Andromeda 2009-11-11 08:32:50