Adding pagination value to json response in Cakephp 3.3

若如初见. 提交于 2019-12-08 18:50:39

I found the answer to the question at: http://florian-kraemer.net/2015/10/cakephp-angularjs-pagination/

However you have to put the validation for pagination after you complete the query otherwise it will always return false;

Here is an example of the code:

    public function index() {

    $query = $this->Table->find();
    if (empty($this->request->params['paging'][$this->Table->alias()])) {
       $paging = false;
    } else {
       $paging = $this->request->params['paging'][$this->Table->alias()];
    }
    $this->set('records', $this->paginate($query));
    $this->set('paging', $paging);
    $this->set('_serialize', ['records', 'paging']);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!