One way to keep the search logic in the model and still paginate in the controller:
Explanation:
Instead of returning actual results from the model, just return all / all search parameters, then paginate as usual. For some examples, such as this simple below, this may seem redundant, but it leaves room for the addition of many more opportunities find(), such as contain, order, group, joins, conditions... etc. etc. And it remains more in accordance with the mantra "Fat models, skinny controllers."
find() , - , .
:
$opts = array('paginate' => true, 'limit'=>20);
$paginateOptions = $this->Event->getEvents($opts);
$this->paginate = $paginateOptions;
$data = $this->paginate('Event');
public function getProducts($opts = null) {
$params = array();
$params['limit'] = 50;
if(!empty($opts['limit'])) $params['limit'] = $opts['limit'];
$paginate = false;
if(isset($opts['paginate'])) {
if($opts['paginate']) $paginate = true;
}
if($paginate) {
return $qOpts;
} else {
$data = $this->find('all', $qOpts);
return $data;
}
}
/ , , .
( .)