Cakephp 3.x Custom Query Pagination

≡放荡痞女 提交于 2019-12-11 03:49:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!