问题
I used in Cakephp 2.x Custom Query Pagination. Now I am trying to migrate a project to Cake 3.
The manual of Cake 3 does not mention Custom Query Pagination any more, and it seems, that the model function paginate / paginateCount which are used for the Custom Query Pagination are not called.
Does anyone know, if this is dropped in Cake 3 ? If so, how can I do pagination with custom queries in cake 3 ?
回答1:
Try this:
public function index()
{
$query = $this->Articles->find('popular')->where(['author_id' => 1]);
$this->set('articles', $this->paginate($query));
}
The doc page: http://book.cakephp.org/3.0/en/controllers/components/pagination.html
回答2:
Try to read these :
Controller/Component/Pagination
View/Helper/Paginator
回答3:
$bookmarks = TableRegistry::get('Bookmarks');
$this->paginate['contain'] = [
'Users' => function (\Cake\ORM\Query $query) {
return $query->select(['email'])
->where([]);
}
];
$bookmarks = $this->paginate($bookmarks);
来源:https://stackoverflow.com/questions/29621449/cakephp-3-x-custom-query-pagination