有没有办法在 CakePHP 2.x 中获取动态加载行为的配置?
Is there a way to get the config for a dynamically loaded behavior in CakePHP 2.x?
示例:
$Model->Behaviors->load('Some.Behaviour', $options);
// Now how do I get $options back from the model?
有没有办法得到$options
? $Model->actsAs
仍然是空的。
这些选项存储在行为本身的 settings
属性 中。您可以使用:
$this->Behaviors->Behavior->settings[''];
例如:
$this->Behaviors->load('Containable', array('hello' => 'world'));
var_dump($this->Behaviors->Containable->settings);
会 return:
array (size=2)
'priority' => int 10
'' =>
array (size=4)
'recursive' => boolean true
'notices' => boolean true
'autoFields' => boolean true
'hello' => string 'world' (length=5)
如您所见,"hello world option" 就在底部。
示例:
$Model->Behaviors->load('Some.Behaviour', $options);
// Now how do I get $options back from the model?
有没有办法得到$options
? $Model->actsAs
仍然是空的。
这些选项存储在行为本身的 settings
属性 中。您可以使用:
$this->Behaviors->Behavior->settings[''];
例如:
$this->Behaviors->load('Containable', array('hello' => 'world'));
var_dump($this->Behaviors->Containable->settings);
会 return:
array (size=2)
'priority' => int 10
'' =>
array (size=4)
'recursive' => boolean true
'notices' => boolean true
'autoFields' => boolean true
'hello' => string 'world' (length=5)
如您所见,"hello world option" 就在底部。