解决yii2 Missing required parameter "id" when instantiating

 

    function actions(){
        return ArrayHelper::merge(parent::actions(), [
            'checkCourseAccess' =>  'common\actions\CheckCourseAccessAction'
        ]);
    }
    function behaviors() {
        return ArrayHelper::merge(parent::actions(),[
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'allow' => true,
                        'matchCallback' => function($rule,$action){
                            if(!$this->getUserId()){
                                return false;
                            }
                            return true;
                        }
                    ],
                ],
            ],
        ]);
    }
behaviors函数使用了权限检测: AccessControl::className(),
那么前面必须先引入,也就是:
function actions(){
        return ArrayHelper::merge(parent::actions(), [
            'checkCourseAccess' =>  'common\actions\CheckCourseAccessAction'
        ]);
    }

否则会报错:
Missing required parameter "id" when instantiating "common\actions\CheckCourseAccessAction".

 

posted @ 2017-07-05 14:55  叨叨的蜗牛  阅读(1727)  评论(0编辑  收藏  举报