解决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".