I'm using CakePHP v2.4.1, and I'm trying to have two separate models be paginated on the same page, through the same controller action (index)
I want to have a NewsPost paginated on a single page, and the EventPost also paginated separately on the same page. Is this bad practice, or is it possible to set conditions to change the $this->paginate variable to paginate properly depending on which model it is on?
My Controller looks like this:
public $uses = array(
'NewsPost',
'NewsPostComment',
'EventPost',
'EventPostComment'
);
public $paginate = array(
'limit' => 9,
'order' => array(
'NewsPost.created' => 'desc'
),
'recursive' => 1,
);
public function index() {
$this->paginate = array(
'limit' => 1,
'order' => array(
'EventPost.created' => 'desc'
),
'recursive' => 1,
);
$this->Paginator->settings = $this->paginate;
$newsPosts = $this->paginate('NewsPost');
$eventPosts = $this->EventPost->find('all');
$this->set(array('newsPosts' => $newsPosts, 'eventPosts' => $eventPosts));
The built-in cake paginator does not seem to allow for the options of paginating separate models, or am I wrong?
Here is the view for pagination:
<?php
$params = $this->Paginator->params();
if ($params['count'] > 0): ?>
<div class="pagination-totals pull-left">
<?php echo $this->Paginator->counter(array('format' => __('{:start} to {:end} of {:count}'))) ?>
</div>
<?php endif; ?>
<?php echo $this->Paginator->numbers(array(
'class' => 'pull-right',
'prev' => '<',
'next' => '>',
));
?>
The problem is, when I choose page two for the NewsPost, it switches to page two for the EventPost, so how can I differentiate between both separate models on the same page using CakePHP pagination?
Thanks