2
votes

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 ?

3
did you find a way to achieve this? - Joost

3 Answers

2
votes

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

0
votes
$bookmarks = TableRegistry::get('Bookmarks');

    $this->paginate['contain'] = [
        'Users' => function (\Cake\ORM\Query $query) {
            return $query->select(['email'])
                         ->where([]);
        }
    ];

    $bookmarks = $this->paginate($bookmarks);