[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ] ]; if ($this->accessControl) { $result['access'] = [ 'class' => AccessControl::className(), // 'only' => [Yii::$app->controller->action->id], 'rules' => [ [ 'actions' => [$this->getActionId()], 'allow' => true, 'matchCallback' => function ($rule, $action) { return true; } ], ], ]; } return $result; } /** * User: wangxj * * 控制器结束后调用函数 * * @params * * @return */ public function beforeAction($action) { $this->triggerTip(); return parent::beforeAction($action); } /** * User: wangxj * * 注册显示右上角提示的js代码 * 只支持 info,error,success,warning * */ protected function triggerTip() { $flashes = \Yii::$app->session->getAllFlashes(); if (count($flashes) > 0) { foreach ($flashes as $type => $flash) { if (is_array($flash)) { foreach ($flash as $msg) { $this->view->registerJs("z.showTip('{$type}','{$msg}')", View::POS_LOAD); } } else { $this->view->registerJs("z.showTip('{$type}','{$flash}')", View::POS_LOAD); } } } } /** * 获取当前控制器的action ID * @param $action string action url */ public function getActionId() { if ($this->accessControl) { $actionID = Yii::$app->controller->action->id; $action = BaseRole::findOne(['ROLE_SYS' => BaseRole::ROLE_SYS_FO, 'CANCEL_FLAG' => 0, 'ROLE_NAME' => Url::to([$actionID])]); $access = Yii::$app->user->identity->MENU_PERMISSION; if ($action == null || !in_array($action->ID, $access)) { throw new ForbiddenHttpException(); } } else { $actionID = Yii::$app->controller->action->id; } return $actionID; } }