{EN} - 3.6.2.1 Including Components in your Controllers
Once our component is finished, we can use it in the application’s controllers by placing the component's name (minus the "Component" part) in the controller’s $components array. The controller will automatically be given a new attribute named after the component, through which we can access an instance of it:
/* Make the new component available at $this->Math,
as well as the standard $this->Session */
var $components = array('Math', 'Session');
/* Make the new component available at $this->Math,as well as the standard $this->Session */var $components = array('Math', 'Session');
Components declared in AppController will be merged with those in your other controllers. So there is no need to redeclare the same component twice.
When including Components in a Controller you can also declare a set of parameters that will be passed onto the Components initialize() method. These parameters can then be handled by the Component.
var $components = array( 'Math' => array( 'precision' => 2, 'randomGenerator' => 'srand' ), 'Session', 'Auth' );
var $components = array('Math' => array('precision' => 2,'randomGenerator' => 'srand'),'Session', 'Auth');
The above would pass the array containing precision and randomGenerator to MathComponent's initialize() method as the second parameter.
This syntax is not implemented by any of the Core Components at this time
{EN} - 3.6.2.1 Including Components in your Controllers
Once our component is finished, we can use it in the application’s controllers by placing the component's name (minus the "Component" part) in the controller’s $components array. The controller will automatically be given a new attribute named after the component, through which we can access an instance of it:
/* Make the new component available at $this->Math,
as well as the standard $this->Session */
var $components = array('Math', 'Session');
/* Make the new component available at $this->Math,as well as the standard $this->Session */var $components = array('Math', 'Session');
Components declared in AppController will be merged with those in your other controllers. So there is no need to redeclare the same component twice.
When including Components in a Controller you can also declare a set of parameters that will be passed onto the Components initialize() method. These parameters can then be handled by the Component.
var $components = array( 'Math' => array( 'precision' => 2, 'randomGenerator' => 'srand' ), 'Session', 'Auth' );
var $components = array('Math' => array('precision' => 2,'randomGenerator' => 'srand'),'Session', 'Auth');
The above would pass the array containing precision and randomGenerator to MathComponent's initialize() method as the second parameter.
This syntax is not implemented by any of the Core Components at this time
