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.

Add CrudAction

The add CrudAction will create a new record if the request is HTTP POST and the data validates.

Relevant links: PHP source code API documentation


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.beforeSave id ("edit" only) Called right before calling Model::saveAll.
id The ID of the record that will be saved
Access and modify the data from the $request object like you normally would in your own controller action
Crud.afterSave success
This event is triggered right after the call to Model::saveAll().
success indicates whether or not the Model::saveAll() call succeed or not.
id is only available if the save was successful.
created whether the record was created or modified.
Crud.beforeRender None Invoked right before the view will be rendered.
This is also before the controllers own beforeRender callback


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.
view NULL The view file to render. If the value is NULL the normal CakePHP behavior will be used
relatedModels true The configuration for the Related Models Listener
saveOptions [
  'validate' => 'first',
  'atomic' => true
The 2nd parameter to Model::saveAll.

By default validation will be done first, and the save will be atomic by wrapping it all in a transaction.

Please see the CakePHP saveAll documentation for more information.
serialize array() View vars to serialize if you use the Crud API.
This property maps to _serialize in CakePHP


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
Related Models Listener Please see the Related Models Listener documentation for usage
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.
saveOptions($saveOptions = NULL) Get or set the saveOptions configuration setting.
If $saveOptions is NULL the current saveOptions will be returned.
If $saveOptions is an array, the setting will be changed.

comments powered by Disqus