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....

Index CrudAction

The index CrudAction paginates over the primary model in the controller.

Relevant links: PHP source code | API documentation

Events

This is a list of events emitted from the CrudAction

In addition to the subject properties listed below, there is also a long list of objects that are always available in all events.
Please see the events documentation for a full list of subject properties and how to use the event system correctly.

Event Subject properties Description
Crud.startup None Called after the Controller::beforeFilter() and before the Crud action
Crud.initialize None Triggered when a CrudAction is going to handle a CakePHP.
Crud.beforePaginate paginator Triggered before Controller::paginate() is called.
The paginator property is a reference to the PaginatorComponent.
If you wish to modify the pagination settings, you should only modify $event->subject->paginator->settings.
Modifying Controller::$paginate will not have any effect during this callback.
Crud.afterPaginate items This event is triggered right after the call to Controller::paginate().
The items property contains all the database record found in the pagination call.
Crud.beforeRender None Invoked right before the view will be rendered.
This is also before the controllers own beforeRender callback

Configuration

This is the configuration options for the Crud action class

Please see the configuration documentation on how to change these settings

Key Default value Description
enabled true If this action is enabled or not.
findMethod all (index)
first (edit, view)
count (delete)
The 1st parameter to Model::find or Model::paginate().
view NULL The view file to render. If the value is NULL the normal CakePHP behavior will be used
viewVar NULL For Index Crud Action the default is plural version of the model name.
Having a model named Post would mean that the viewVar would be posts by default.

For View Crud Action the default is singular version of the model name.
Having a model named Post would mean that the viewVar would be post by default.
serialize array() View vars to serialize if you use the Crud API.
This property maps to _serialize in CakePHP

Methods

This is a list of the most relevant public methods in the Crud action class.

For a full list please see the full API documentation

Method Description
view($view = NULL) Get or set the view configuration setting.
If $view is NULL the current view will be returned.
If $view is a string, the setting will be changed.
viewVar($viewVar = NULL) Get or set the viewVar configuration setting.
If $viewVar is NULL the current viewVar will be returned.
If $viewVar is a string, the setting will be changed.
findMethod($method = NULL) Get or set the findMethod configuration setting.
If $method is NULL the current findMethod will be returned.
If $method is a string, the setting will be changed.

Query string parameters

You can easily add query string pagination to your Api index actions by adding Api Pagination and enabling query strings. This will give api-requesters the possibility to create custom data collections using GET parameters in the URL (e.g. http://example.com/controller.{format}?key=value)

The following query string pagination parameters will automatically become available:

  • limit: an integer limiting the number of results
  • sort: the string value of a fieldname to sort the results by
  • direction: either asc or desc (only works in combination with the sort parameter)
  • page: an integer pointing to a specific data collection page

Please also see the CakePHP documentation on Pagination

Please also see the CakePHP documentation on out of range page requests

Setup by enabling Api Pagination as described here

Then enable query string pagination by adding this to your /Controller/AppController.php file

<?php
  public $paginate = array(
    'paramType' => 'querystring'
  );
?>



comments powered by Disqus