Base class for an individual Component. Components provide reusable bits of controller logic that can be composed into a controller. Components also provide request life-cycle callbacks for injecting logic at specific points.
Like Controller and Table, this class has an initialize() hook that you can use to add custom 'constructor' logic. It is important to remember that each request (and sub-request) will only make one instance of any given component.
Components can provide several callbacks that are fired at various stages of the request cycle. The available callbacks are:
beforeFilter(EventInterface $event)
Called before Controller::beforeFilter() method by default.startup(EventInterface $event)
Called after Controller::beforeFilter() method, and before the
controller action is called.beforeRender(EventInterface $event)
Called before Controller::beforeRender(), and before the view class is loaded.afterFilter(EventInterface $event)
Called after the action is complete and the view has been rendered but
before Controller::afterFilter().beforeRedirect(EventInterface $event, $url, Response $response)
Called before a redirect is done. Allows you to change the URL that will
be redirected to by returning a Response instance with new URL set using
Response::location(). Redirection can be prevented by stopping the event
propagation.While the controller is not an explicit argument for the callback methods it is the subject of each event and can be fetched using EventInterface::getSubject().
ComponentRegistry is a registry for loaded components
Handles loading, constructing and binding events for component class objects.
Application controller class for organization of business logic. Provides basic functionality, such as rendering views inside layouts, automatic model availability, redirection, callbacks, and more.
Controllers should provide a number of 'action' methods. These are public
methods on a controller that are not inherited from Controller.
Each action serves as an endpoint for performing a specific action on a
resource or collection of resources. For example adding or editing a new
object, or listing a set of objects.
You can access request parameters, using $this->getRequest(). The request object
contains all the POST, GET and FILES that were part of the request.
After performing the required action, controllers are responsible for
creating a response. This usually takes the form of a generated View, or
possibly a redirection to another URL. In either case $this->getResponse()
allows you to manipulate all aspects of the response.
Controllers are created based on request parameters and
routing. By default controllers and actions use conventional names.
For example /posts/index maps to PostsController::index(). You can re-map
URLs using Router::connect() or RouteBuilder::connect().
CakePHP fires a number of life cycle callbacks during each request. By implementing a method you can receive the related events. The available callbacks are:
beforeFilter(EventInterface $event)
Called before each action. This is a good place to do general logic that
applies to all actions.beforeRender(EventInterface $event)
Called before the view is rendered.beforeRedirect(EventInterface $event, $url, Response $response)
Called before a redirect is done.afterFilter(EventInterface $event)
Called after each action is complete and after the view is rendered.Factory method for building controllers for request.
Error Handling Controller
Controller used by ErrorHandler to render error views.