开发者

CakePHP passing data to component before instantiation

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜