Reputation: 13
Currently, I am working on Cakephp Application. I want to first paginate and then sort the paginated data according to the condition show below or the other way around. First sort the data and then paginate it. Any hints on how to approach the problem. I am just one week familiar with cakephp.
$condition[] = 'Banner.customer_id = "'.$loggedUserId.'"';
$this->Banner->recursive = 2;
$this->paginate = array(
'limit' => 20,
);
$data = $this->paginate('Banner', $condition);
$data_sorted = $this->Banner->find('all',array('order'=>array("Banner.created DESC")));
$this->set('loggedInUserId', $loggedUserId);
$this->set('savecrit', $savecrit);
$this->set('Banners', $data_sorted);
Upvotes: 1
Views: 358
Reputation: 171
Try this:
$this->paginate = array(
'conditions' => array('Banner.customer_id' => $loggedUserId),
'limit' => 20,
'order' => array('id' => 'DESC'),
);
Upvotes: 1