Même si dans la plupart des cas, une bonne solution serait de rearchitect votre interface utilisateur de supprimer la nécessité pour le double pagination, ce qui suit est une solution de travail:
Tout d'abord, dans votre contrôleur vous substituez la fonction paginate() Cake à chercher la clé paginator:
/**
* Handles automatic pagination of model records.
*
* @param mixed $object Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel')
* @param mixed $scope Conditions to use while paginating
* @param array $whitelist List of allowed options for paging
* @return array Model query results
* @access public
* @link http://book.cakephp.org/view/165/Controller-Setup
*/
function paginate($object = null, $scope = array(), $whitelist = array(), $key = null) {
$results = parent::paginate($object, $scope, $whitelist);
if ($key) {
$this->params['paging'][$key] = $this->params['paging'][$object];
unset($this->params['paging'][$object]);
}
return $results;
}
Puis
/**
* undocumented function
*
* @param string $key
* @return void
* @access public
*/
function _pageForPagination($by) {
$page = 1;
$samekey = isset($this->params['named']['by']) && $this->params['named']['by'] == $by;
$pageInUrl = isset($this->params['named']['page']);
if ($samekey && $pageInUrl) {
$page = $this->params['named']['page'];
}
$this->passedArgs['page'] = $page;
return $page;
}
/**
* FIXME: Wrapper for Cake's pagination
* Change pagination criteria on the fly (conditions, grouping, order, limit)
*
* @param string $model
* @param string $criteria
* @return void
* @author Andrew
*/
function _paginateBy($key) {
$this->User->unbindModel(array('hasMany' => array('UserImage')), false);
$this->paginate['User'] = am($this->User->getCriteria($key), array('page' => $this->_pageForPagination($key)));
return $this->paginate('User', array(), array(), $key);
}
utiliser ensuite comme si dans le contrôleur: $ this-> s et ('byJoinDate', $ this -> _ paginateBy ('random'));
Dans le modèle: echo $ paginator-> prev ('prev', array ('model' => $ par, 'class' => 'back'), null, array ('model' => $ par, 'class' => 'désactivé arrière'));
Veuillez lire ma réponse à une question similaire: http: // stackoverflow.com/a/21211278/2486198 – Mitja