0

PaginationRecall 组件让我很头疼,它让我的应用程序崩溃。

我有一个区域视图,我可以用 /views/[number of region] 调用它

我发现崩溃的原因是它想回到第 5 页,尽管 URL 更改为只有 1 或 2 页的不同区域。我更新到最新的 cakePHP 版本 [v2.3.5],因为提到了“防止分页限制溢出最大整数值”的修复但更新并没有解决我的问题。不确定这是 PaginationRecal 组件还是 Paginator 本身的问题。

例如; 我可以浏览到 url ../regions/view/1/page:5 离开该页面,然后返回时一切正常[它记得最后一页] 但是当将 url 更改为不同的区域时 ../regions/view/56 / 它因错误而崩溃:错误:在此服务器上找不到请求的地址“/regions/view/56”。堆栈跟踪

CORE/Cake/Controller/Controller.php 第 1074 行

  • @deprecated 改用 PaginatorComponent */ public function paginate($object = null, $scope = array(), $whitelist = array()) { return $this->Components->load('Paginator', $this->paginate )->分页($object, $scope, $whitelist); }

起初我不理解这次崩溃,直到我发现它与页码有关。仅在第一页上浏览时不会弹出该问题。我该如何解决这个问题?

我在 /app/Controller/AppController.php 中添加了 PaginatorRecall 组件

 public $components = array('PaginationRecall');

这是组件:http ://bakery.cakephp.org/articles/Zaphod/2012/03/27/paginationrecall_for_cakephp_2_x

非常感谢任何帮助。

4

2 回答 2

0

解决了

在调查了 PaginatorRecall 组件在做什么之后,我发现它只过滤掉了 page:number 并将其存储在会话中。

我添加了一条规则来确定区域是否已更改,如果已更改,则将页面重置为 page:1

希望这也有助于其他人使用此组件。

于 2013-05-23T08:04:45.087 回答
0

这是我对这个问题的解决方案以及PaginationRecall在第一页上的错误。当然,它不是最佳解决方案,但它是功能性的。

class PaginationRecallComponent extends Component {
    var $components = array('Session');
    var $Controller = null;

    function initialize(&$controller) {
        $this->Controller = & $controller;
        $options = array_merge($this->Controller->request->params, $this->Controller->params['url'], $this->Controller->passedArgs
        );
        $vars = array('page', 'sort', 'direction', 'filter');
        $keys = array_keys($options);
        $count = count($keys);
        for ($i = 0; $i < $count; $i++) {

            if (!in_array($keys[$i], $vars) || !is_string($keys[$i])) {

                unset($options[$keys[$i]]);
            }
        }
        //save the options into the session
        if ($options) {
            if ($this->Session->check("Pagination.{$this->Controller->modelClass}.options")) {
                $options = array_merge($this->Session->read("Pagination.{$this->Controller->modelClass}.options"), $options);
            }
            $this->Session->write("Pagination.{$this->Controller->modelClass}.options", $options);
            $this->Session->write("region",$this->Controller->modelClass.'/'.$this->Controller->view);
        }
        $region=$this->Session->read('region');
        //recall previous options       
        if ($this->Session->check("Pagination.{$this->Controller->modelClass}.options") && $region==$this->Controller->modelClass.'/'.$this->Controller->view ) {
            $options = $this->Session->read("Pagination.{$this->Controller->modelClass}.options");
            if(!isset($this->Controller->params['named' ]['page']) && isset($this->Controller->params['named' ]['direction']) )               
            {
                $options['page']=1;
            }
            $this->Controller->passedArgs = array_merge($this->Controller->passedArgs, $options);
            $this->Controller->request->params['named'] = $options;
        }
    }
}
于 2014-01-05T14:10:31.837 回答