0

PaginationRecall コンポーネントが頭痛の種で、アプリケーションがクラッシュしました。

リージョン ビューがあり、/views/[number of region] で呼び出すことができます

クラッシュの理由は、URL が 1 ページまたは 2 ページしかない別のリージョンに変更されているにもかかわらず、Page:5 に戻りたいことが原因であることがわかりました。「ページネーション制限による最大整数値のオーバーフローの防止」の修正について言及があったため、最新の 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 )->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

これは、この問題と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 に答える