Welcome to the Cookbook

loading...

3.6.3 Component callbacks

Todavia no hay una traducion de este texto. Por favor ayudanos y traducirla.. Mas info sobre traduciones

While components provide a way to create reusable controller code, that performs a specific task. Components also offer a way to hook into the general application flow. There are 5 built-in hooks, and more can be created dynamically using Component::triggerCallback.

The core callbacks are:

  • initialize() is fired before the controller's beforeFilter, but after models have been constructed.
  • startup() is fired after the controllers' beforeFilter, but before the controller action.
  • beforeRender() is fired before a view is rendered.
  • beforeRedirect() is fired before a redirect is done from a controller. You can use the return of the callback to replace the url to be used for the redirect.
  • shutdown() is fired after the view is rendered and before the response is returned.

You can add additional methods to your components, and call those methods at any time by using Component::triggerCallback(). If you had added a onAccess callback to your components. You could fire that callback from within the controller by calling $this->Component->triggerCallback('onAccess', $this);

You can disable the callbacks triggering by setting the enabled property of a component to false.