我想在我的控制器中使用both beforeAction()和behaviors()method.
如果我beforeAction()在我的代码中添加方法比behaviors()方法不起作用.
如果我删除 beforeAction()方法比behaviors()方法工作.
我不想删除,beforeAction()因为它用于禁用ajax调用的csrf令牌.
public function beforeAction($action)
{
if($action->id =='ignore' || $action->id =='accept')
{
$this->enableCsrfValidation = false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
我想使用behaviors()方法进行身份验证.
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['create','index','update','change','view','page','active','list'],
'rules' => [
[
'actions' => ['create','index','update','change','view','page','active','list'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action)
{
echo "string";
die;
},
],
],
'denyCallback' => …Run Code Online (Sandbox Code Playgroud)