Cakephp Classroom image

pankaj
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26|Last
Lessons:-Controllers

/* Make the new component available at $this->Math,
as well as the standard $this->Session */
public $components = array(’Math’, ’Session’);
Components declared in AppController will be merged with those in your other controllers. So there is
no need to re-declare the same component twice.
When including Components in a Controller you can also declare a set of parameters that will be passed on
to the Component’s constructor. These parameters can then be handled by the Component:
public $components = array(
’Math’ => array(
’precision’ => 2,
’randomGenerator’ => ’srand’
),
’Session’, ’Auth’
);
The above would pass the array containing precision and randomGenerator to
MathComponent::__construct() as the second parameter. By convention, any settings that
have been passed that are also public properties on your component will have the values set based on the
settings.
Using other Components in your Component
Sometimes one of your components may need to use another component. In this case you can include
other components in your component the exact same way you include them in controllers - using the
$components var:
// app/Controller/Component/CustomComponent.php
App::uses(’Component’, ’Controller’);
class CustomComponent extends Component {
// the other component your component uses
public $components = array(’Existing’);
public function initialize(Controller $controller) {
$this->Existing->foo();
}
public function bar() {
// ...
}
}
// app/Controller/Component/ExistingComponent.php
App::uses(’Component’, ’Controller’);
class ExistingComponent extends Component {
public function foo() {
// ...
}
}

 
 
 

pankaj

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)