From 7a5315615ab17e75e9b50410761cabfc52295516 Mon Sep 17 00:00:00 2001 From: Hans-Joachim Michl Date: Sat, 2 Sep 2017 08:41:15 +0200 Subject: [PATCH] Add example of custom controller action (#207) Add example of custom controller action Refs #206 --- docs/customizing-templates.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/customizing-templates.rst b/docs/customizing-templates.rst index c7130b92..35475596 100644 --- a/docs/customizing-templates.rst +++ b/docs/customizing-templates.rst @@ -33,6 +33,35 @@ title for any of the fields by using the ``scaffold.fields`` configuration // The rest of the fields to display here ]); +Adding Controller Actions to utilize Crud Actions +------------------------------------------------- + +It's easy to add an action to a controller that makes use of another +*CrudView* action. + +This does use the template provided by the edit action: + +.. code-block:: php + + public function account() { + $this->Crud->mapAction('account', [ + 'className' => 'Crud.Edit', + 'view' => 'edit', + ]); + return $this->Crud->execute(null, $this->Auth->user('id')); + } + +By default, it can be overwritten by providing a custom ``register.ctp``: + +.. code-block:: php + + public function register() { + $this->Crud->mapAction('register', [ + 'className' => 'Crud.Add', + ]); + return $this->Crud->execute(); + } + Overriding Template Elements ----------------------------