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.


Listeners are an easy way to extend Crud functionality

They can hook into all the Crud events emitted from CrudComponent or the CrudActions

Most of the functionality in Crud is build with listeners, keeping the CrudAction code lean and simple, and Crud flexible

Naming convention for Listeners is “Camelize” e.g. Api and RelatedModels - just like CakePHP for Helpers, Components and Behaviors


The CrudComponent API for managing listeners


Get a listener by its name

public function beforeFilter() {
	$listener = $this->Crud->listener('Api');
	$listener = $this->Crud->listener('Translations');
	$listener = $this->Crud->listener('RelatedModels');


Add a Crud listener on the fly

public function beforeFilter() {
	// Shorthand to add a listener in the Crud plugin

	// Add a listener in a specific plugin with a specific class name
	$this->Crud->addListener('Api', 'Crud.Api');

	// Add a listener in a specific plugin with a specific class name and provide default configuration
	$this->Crud->addListener('Api', 'Crud.Api', array('some' => 'defaults'));

	// Add a listener from Crud and provide default configuration
	$this->Crud->addListener('Api', null, array('some' => 'defaults'));


Remove a listener, and detach it from the CakePHP event manager (if attached)

public function beforeFilter() {

comments powered by Disqus