Skip to content

Instantly share code, notes, and snippets.

@hscstudio
Last active February 5, 2016 04:00
Show Gist options
  • Save hscstudio/84c5ec469f435d408b02 to your computer and use it in GitHub Desktop.
Save hscstudio/84c5ec469f435d408b02 to your computer and use it in GitHub Desktop.
'on beforeAction' => function($event){
$action = $event->action;
$moduleID = $action->controller->module->id;
$controllerID = $action->controller->id;
$actionID = $action->id;
$user = \Yii::$app->user;
$userID = $user->id;
if(!in_array($controllerID,['default','site'])){
$auth = \app\models\Auth::find()
->where([
'module' => $moduleID,
'controller' => $controllerID,
'action' => $actionID,
'user_id' => $userID,
])
->count();
if($auth==0) {
if (!$action instanceof \yii\web\ErrorAction) {
if ($user->getIsGuest()) {
$user->loginRequired();
} else {
throw new \yii\web\ForbiddenHttpException('Anda tidak diizinkan untuk mengakses halaman ' . $action->id . ' ini!');
}
}
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment