Although in most cases, the correct solution would be to rebuild your user interface to eliminate the need for double pagination, the following working solution:
First, in your controller, you override the cake paginate () function to find the delimiter key:
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;
}
Then
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;
}
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);
}
Then use it also in the controller: $ this-> set ('byJoinDate', $ this → _ paginateBy ('random'));
: echo $paginator- > prev ('prev', array ('model' = > $by, 'class' = > 'back'), null, array ('model' = > $by, 'class' = > 'disabled '));