I have a component that uses some classes to do the job it's supposed to do. I need to pass data to it so it instantiates objects that it's going to need. How can I do it?
Should I use initialize(&$Controller, $settings = array())
callback? If so, how can I pop开发者_开发技巧ulate $settings
?
Component::initialize
is usually a good place to do this and the $settings
variable can be populated through your Controller::$components
array:
public $components = array('Foobar' => array('baz' => 42));
// array('baz' => 42) will be passed as the second argument ($settings) to
// FoobarComponent::initialize(&$Controller, $settings)
精彩评论