【发布时间】:2014-03-11 06:58:49
【问题描述】:
我有一个从数据库中检索到的零件表和一个带有选择标记的表单,其中列出了 PartTypes 和一个
[刷新] 按钮。这些用于过滤表格以仅显示与所选类型匹配的部分。
该表为性能进行了分页。当我从第 1 页开始时,我可以成功过滤我的数据表
使用我的选择和刷新按钮,但如果我通过分页器离开第 1 页,并尝试
使用新的 PartType 刷新页面(而不是全部可见),我收到以下错误
错误:在此服务器上找不到请求的地址“/product/parts/index/page:2”。
我已经阅读了 PaginatorComponent 和 PaginatorHelper 文档,但看不到如何 在过滤我的数据之前重置页面。我错过了什么?
/Controller/PartsController.php
public $paginate = array(
'limit' => 12,
'page' => 1,
'order' => array('Part.name' => 'asc' )
);
public function index() {
// ...
// array $qcond holds the query properties for filtering parts
if (count($qcond) > 0)
$this->paginate['conditions'] = $qcond;
// ...
$this->set('parts', $this->paginate());
}
app/View/Parts/index.ctp
<?php
echo $this->Paginator->prev(__('«'), array('tag' => 'li'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
echo $this->Paginator->numbers(array('separator' => '','currentTag' => 'a', 'currentClass' => 'active','tag' => 'li','first' => 1));
echo $this->Paginator->next(__('»'), array('tag' => 'li','currentClass' => 'disabled'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
?>
问题已解决:问题不在分页器中,而在表单中。必须手动将表单的 url 设置为不使用 /page:2,而不是让 CakePhp 自己推断 url。
【问题讨论】:
标签: cakephp pagination