示例:
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
仍为空。
答案 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选项”就在底部。