如何(将CakePhp分页重置为第1页

时间:2014-02-12 18:33:43

标签: cakephp pagination

我有一个从数据库中检索到的零件表和一个带有选择标签的表格,其中列出了PartTypes和a [刷新]按钮。这些用于过滤表格,仅显示与所选类型匹配的部分 该表针对性能进行了分页。当我开始第1页时,我可以成功过滤我的数据表 使用我的选择和刷新按钮,但如果我通过Paginator离开第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());
}

应用程序/视图/零件/ 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'));
?>

问题解决了:问题不在Paginator中,而是在Form中。不得不手动将表单的url设置为不使用/ page:2,而不是让CakePhp自己推断出url。

1 个答案:

答案 0 :(得分:0)

在Cakephp 2.x中,您可以通过在Controller中使用以下代码来重置页面:

$this->request->params['named']['page']=1;
相关问题