Configuration of Crud is done through the Crud component
- either on the fly
anywhere in you application, or by providing the configuration in the
Controller::$components
property.
Assuming you have followed the installation guide we will now begin the actual configuration of Crud.
Crud is loaded like any other Component
in CakePHP - simply by adding it to
the $components
variable in the controller
class AppController extends \Cake\Controller\Controller {
public $components = ['Crud.Crud'];
}
At this time, the Crud Component is loaded and ready for usage.
However, Crud has not been configured to handle any controller actions yet.
Configuring Crud to handle actions is simple.
The list of actions is provided either as Component
configuration, or on the
fly.
An example of Component
configuration:
class AppController extends \Cake\Controller\Controller {
public $components = [
'Crud.Crud' => [
'actions' => ['Crud.Index']
]
];
}
An example of on the fly enabling an Crud action:
class AppController extends \Cake\Controller\Controller {
public function beforeFilter(\Cake\Event\Event $event) {
$this->Crud->mapAction('index', 'Crud.Index');
}
}
The examples above are functionally identical, and instructs Crud to handle the
index
action in controllers using Crud.Index
action class.
Note
If you do not wish for Crud to be enabled across all controllers, or even use
all actions
provided by Crud
you can pick and chose which to use. Crud will not force take-over any
application logic, and you can enable/disable
them as you see fit.
Note
Each Crud Action have a different set of configuration settings, please see their individual documentation page for more information.
Passing in configuration for an action is simple.
Note
In the examples below, we reconfigure the Index Action to render
my_index.ctp
instead of index.ctp
An example of Component
configuration
class AppController extends \Cake\Controller\Controller {
public $components = [
'Crud.Crud' => [
'actions' => [
'index' => ['className' => 'Crud.Index', 'view' => 'my_index']
]
]
];
}
An example of on the fly enabling an Crud action with configuration
class AppController extends \Cake\Controller\Controller {
public function beforeFilter(\Cake\Event\Event $event) {
$this->Crud->mapAction('index', [
'className' => 'Crud.Index',
'view' => 'my_index'
]);
}
}
Crud provides the default CRUD
actions out of the box.
It’s possible to create your own Crud Action
as well, or overwrite the
built-in ones.
Simply provide the className
configuration key for an action, and Crud will
use that one instead.
Note
Each Crud Listener have a different set of configuration settings, please see their individual documentation page for more information.