例如?我有两个BaseController和ChildController。 我想从BaseController附加行为,但是当behaviors(Child)时优先级具有behaviors(Base)。
基础:
cmake -H<source path> -B<build path> -DCMAKE_INSTALL_PREFIX=<install path>
孩子:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'matchCallback' => function ($rule, $action) {
return ...(true or false)...;
}
],
],
],
];
}
和逻辑:
如果父级返回false,则访问被拒绝
如果父级返回true,那么子级返回
如何?
答案 0 :(得分:0)
这必须对您有帮助
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['access'] = [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'matchCallback' => function ($rule, $action) {
return ... can ...;
},
],
],
];
return $behaviors;
}
其他方式可能是:
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['access']['rules'][] = [
'allow' => true,
'matchCallback' => function ($rule, $action) {
return ... can ...;
},
];
return $behaviors;
}