开发者

CakePHP passing data to component before instantiation

开发者 https://www.devze.com 2023-01-29 14:57 出处:网络
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?

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消