I had been working on a project and stuck in a problem where a view needs two pagination on same model with different conditions in Cakephp 3.
For eg. opened and closed support tickets listing on the same view.
The following is my code. Can someone help me?
//Opened status pagination
$opened_paginate = [
'contain' => ['Comments'],
'conditions' => [
'AND' => ['SupportTickets.status' => '1']
],
'order' => ['SupportTickets.id' => 'DESC'],
'limit' => 1
];
// Closed status pagination
$closed_paginate = [
'contain' => ['Comments'],
'conditions' => [
'AND' => ['SupportTickets.status' => '2']
],
'order' => ['SupportTickets.id' => 'DESC'],
'limit' => 1
];
$this->set('opened', $this->Paginator->paginate(
$this->SupportTickets->find(),
$opened_paginate
));
$this->set('closed', $this->Paginator->paginate(
$this->SupportTickets->find(),
$closed_paginate
));