I have pagination working fine for when $this->paginate is called once in an action, but it does not appear to be very good support for multiple calls. Here is what I\'m loo
Since there was not much activity on this, I went ahead and did the reasonable thing and figured out a workaround. Below is what I came up with:
Controller:
function index() {
$active = $this->paginate('Post', array('Post.status'=>1));
$activePaging = $this->request->params['paging']['Post'];
$inactive = $this->paginate('Post', array('Post.status'=>0));
$inActivePaging = $this->request->params['paging']['Post'];
$this->set('active', $active);
$this->set('inactive', $inactive);
$this->request->params['paging']['Active'] = $activePaging;
$this->request->params['paging']['InActive'] = $inActivePaging;
unset($this->request->params['paging']['Post']);
}
public function paginate() {
if ($this->request->is('ajax')) {
$model = $this->request->params['named']['model'];
$status = $model === 'Active' ? 1 : 0;
$posts = $this->paginate('Post', array('Post.status'=>$status));
$paging = $this->request->params['paging']['Post'];
unset($this->request->params['paging']['Post']);
$this->request->params['paging'][$model] = $paging;
$this->set('posts', $posts);
$this->set('model', $model);
$this->render('/Posts/ajax_posts_paginated', 'ajax');
}
}
Views: (simplified)
index.ctp
Inactive Posts
element('posts_table_paginated', array('posts'=>$inactive, 'model'=>'InActive')); ?>
Active Posts
element('posts_table_paginated', array('posts'=>$active, 'model'=>'Active')); ?>
elements/posts_table_paginated.ctp
Paginator->options(array(
'update' => '#'.$model,
'evalScripts' => true,
'url'=> array('controller'=>'posts', 'action'=>'paginate', 'model'=>$model)
));
?>
Paginator->sort('id', 'ID', array('model'=>$model)); ?>
Paginator->sort('title', 'Title', array('model'=>$model)); ?>
Paginator->sort('created', 'Created', array('model'=>$model)); ?>
Created by
params['paging'][$model]['count'] > 0) {
?>
Paginator->prev(__('previous'), array('tag' => 'li', 'model'=>$model), null, array('tag'=>'li', 'class'=>'prev off'));
echo $this->Paginator->numbers(array('tag'=>'li', 'model'=>$model, 'separator' => false));
echo $this->Paginator->next(__('next'), array('tag' => 'li', 'model'=>$model), null, array('tag'=>'li', 'class'=>'next off'));
?>
Js->writeBuffer();
?>