Rest api cakephp -3 pagination

For web we are using Paginate component & for view we used the paginator helper,

what is the standard way to enable pagination i am using following technology.

  • Cakephp-3 php MVC framework as Back-end Tech
  • Angular-js 4 as fronted

Cakephp 3 code


public function beforeRender(Event $event)
    if ($this->request->param('paging') !== false &&
        in_array($this->response->type(), ['application/json', 'application/xml'])
    ) {
        $this->set('paging', current($this->request->param('paging')));
    if (!array_key_exists('_serialize', $this->viewVars) &&
        in_array($this->response->type(), ['application/json', 'application/xml'])
    ) {
        $this->set('_serialize', true);

Don’t forget to pass the paging parameter in url.


After that you should receive following array

"paging": {
    "Posts": {
        "finder": "all",
        "page": 1,
        "current": 6,
        "count": 6,
        "perPage": 10,
        "prevPage": false,
        "nextPage": false,
        "pageCount": 1,
        "sort": null,
        "direction": false,
        "limit": null,
        "sortDefault": false,
        "directionDefault": false

About Hiren Kubavat

This entry was posted in API, cakephp-3 and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s