Fork me on GitHub
Heads up!
These docs are for Crud v3 - that only works with CakePHP 2.x. For CRUD v4 docs please go to the new documentation site
The CRUD v4 documentation has been completely rewritten, and since CRUD v3 and CRUD v4 API is ~95% identical, it may be worth a look for CRUD v3 users as well until v4 docs are backported for v3.
...toc....

Api Pagination

Adds pagination information to the API responses

Setup

This feature requires the Api listener to work

Attach it on the fly in your controller beforeFilter

This is recommended if you want to attach it only to specific controllers and actions

<?php
class SamplesController extends AppController {

  public function beforeFilter() {
    $this->Crud->addListener('Api');
    $this->Crud->addListener('ApiPagination');
  }

}
?>

Attach it using components array

This is recommended if you want to attach it to all controllers, application wide

<?php
class SamplesController extends AppController {

  public $components = [
    'RequestHandler',
    'Crud.Crud' => [
      'actions' => ['index', 'view'],
      'listeners' => ['Api', 'ApiPagination']
    ];

}
?>

Configuration

Optionally enable query string parameters for your index actions as described here

Example output

{
   "success": true,
   "data":[

   ],
   "pagination":{
      "page_count": 13,
      "current_page": 1,
      "count": 25,
      "has_prev_page": false,
      "has_next_page": true
   }
}



comments powered by Disqus