/** * 访问角色 * @return bool */ protected function checkRole() { /* @var User $current_user */ $current_user = Yii::$app->user->identity; if (!is_array($this->allowRoles)) { return false; } if (in_array('*', $this->allowRoles)) { return true; } if (in_array($current_user->role, $this->allowRoles)) { return true; } 1 or Log::record(['uid' => Yii::$app->user->id, 'type' => Log::TYPE_PERMISSION_DENY, 'action' => Url::current(), 'detail' => "用户[ {$current_user->username} ]以[ {$current_user->role} ]权限访问「{$this->name}」模块被拒绝。访问URL:" . Yii::$app->request->absoluteUrl]); return false; }