有没有办法在CakePHP 2.x中获取动态加载行为的配置?

时间:2015-05-27 10:35:14

标签: cakephp-2.6

示例:

function isInCodes($code, $codes) {
    $codes = json_encode($codes); // serialize array of objects to json
    $codes = json_decode($codes, true); // unserialize json to associative array
    $codes = array_column($codes, 'code'); // build 1 dimensional array of code fields
    return in_array($code, $codes); // check if exists
}

if(!isInCodes($discount_code, $valid_codes)) {
// do something
}

有没有办法获得$Model->Behaviors->load('Some.Behaviour', $options); // Now how do I get $options back from the model? $options仍为空。

1 个答案:

答案 0 :(得分:1)

这些选项存储在Behavior本身的settings属性中。你可以使用:

来实现它
$this->Behaviors->Behavior->settings[''];

例如:

$this->Behaviors->load('Containable', array('hello' => 'world'));
var_dump($this->Behaviors->Containable->settings);

会回来:

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选项”就在底部。