PHP Class Cake\Controller\Component

### Initialize hook 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. ### Life cycle callbacks Components can provide several callbacks that are fired at various stages of the request cycle. The available callbacks are: - beforeFilter(Event $event) Called before the controller's beforeFilter method by default. - startup(Event $event) Called after the controller's beforeFilter method, and before the controller action is called. - beforeRender(Event $event) Called before the Controller beforeRender, and before the view class is loaded. - shutdown(Event $event) Called after the action is complete and the view has been rendered but before Controller::afterFilter(). - beforeRedirect(Event $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 Event::subject().
See also: Cake\Controller\Controller::$components
Inheritance: implements Cake\Event\EventListenerInterface, use trait Cake\Core\InstanceConfigTrait, use trait Cake\Log\LogTrait
显示文件 Open project: cakephp/cakephp Class Usage Examples

Public Properties

Property Type Description
$components array Other Components this component uses.
$request Cake\Network\Request Request object
$response Cake\Network\Response Response object

Protected Properties

Property Type Description
$_componentMap array A component lookup table used to lazy load component objects.
$_defaultConfig array These are merged with user-provided config when the component is used.
$_registry Cake\Controller\ComponentRegistry Component registry class used to lazy load components.

Public Methods

Method Description
__construct ( Cake\Controller\ComponentRegistry $registry, array $config = [] ) Constructor
__debugInfo ( ) : array Returns an array that can be used to describe the internal state of this object.
__get ( string $name ) : mixed Magic method for lazy loading $components.
implementedEvents ( ) : array Get the Controller callbacks this Component is interested in.
initialize ( array $config ) : void Constructor hook method.

Method Details

__construct() public method

Constructor
public __construct ( Cake\Controller\ComponentRegistry $registry, array $config = [] )
$registry Cake\Controller\ComponentRegistry A ComponentRegistry this component can use to lazy load its components
$config array Array of configuration settings.

__debugInfo() public method

Returns an array that can be used to describe the internal state of this object.
public __debugInfo ( ) : array
return array

__get() public method

Magic method for lazy loading $components.
public __get ( string $name ) : mixed
$name string Name of component to get.
return mixed A Component object or null.

implementedEvents() public method

Uses Conventions to map controller events to standard component callback method names. By defining one of the callback methods a component is assumed to be interested in the related event. Override this method if you need to add non-conventional event listeners. Or if you want components to listen to non-standard events.
public implementedEvents ( ) : array
return array

initialize() public method

Implement this method to avoid having to overwrite the constructor and call parent.
public initialize ( array $config ) : void
$config array The configuration settings provided to this component.
return void

Property Details

$_componentMap protected_oe property

A component lookup table used to lazy load component objects.
protected array $_componentMap
return array

$_defaultConfig protected_oe property

These are merged with user-provided config when the component is used.
protected array $_defaultConfig
return array

$_registry protected_oe property

Component registry class used to lazy load components.
protected ComponentRegistry,Cake\Controller $_registry
return Cake\Controller\ComponentRegistry

$components public_oe property

Other Components this component uses.
public array $components
return array

$request public_oe property

Request object
public Request,Cake\Network $request
return Cake\Network\Request

$response public_oe property

Response object
public Response,Cake\Network $response
return Cake\Network\Response