未知属性–行为方法的yii \ base \ UnknownPropertyException

时间:2019-05-29 06:56:05

标签: yii2

我在behavior()方法中设置了一些属性,但出现此错误

public function behaviors()
{
    return [
        'access'=>[
            'class'=> AccessControl::className(),
            'only'=>['create','update'],
            'rules'=>[
                'allow'=>true,
                'roles'=>['@'],
            ],


        ],
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => [
                'delete' => ['POST'],
            ],
        ],
    ];
}

请有人看到它来解决

2 个答案:

答案 0 :(得分:0)

AccessControl::$rules应该是规则数组,因此您需要类似以下内容:

'access' => [
    'class' => AccessControl::className(),
    'only' => ['create','update'],
    'rules' => [
        [
            'allow' => true,
            'roles' => ['@'],
        ],
    ],
],

答案 1 :(得分:-1)

只需按照以下代码进行更改

'access'=>[
            'class'=> AccessControl::className(),
            'rules'=>[
                'actions'=>['create','update'],
                'allow'=>true,
                'roles'=>['@'],
            ],