CakePHP 2.x 分页记忆

您是否在 CakePHP 1.x 中使用过 PaginationRecall 组件,并想知道为什么它在 CakePHP 2.x 中不起作用?在寻找一种保持分页页面或排序的方法吗?我修改了 mattc 的旧 PaginationRecall 组件,使其在 CakePHP 2.x 下工作。以下是修改后的代码。

 `

<?php
/*
*PaginationRecallCakePHPComponent
*Copyright(c)2008MattCurry
*www.PseudoCoder.com
*
*@authormattc<[email protected]>
*@version2.0
*@licenseMIT
*Changedtocakephp2.xby
*
*/

classPaginationRecallComponentextendsComponent{
var$components=array('Session');
var$Controller=null;

functioninitialize(&$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]]);
}
}

//savetheoptionsintothesession
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);
}

//recallpreviousoptions
if($this->Session->check("Pagination.{$this->Controller->modelClass}.options")){
$options=$this->Session->read("Pagination.{$this->Controller->modelClass}.options");
$this->Controller->passedArgs=array_merge($this->Controller->passedArgs,$options);
$this->Controller->request->params['named']=$options;
}
}
}
?>


`