Last active
February 5, 2016 04:00
-
-
Save hscstudio/84c5ec469f435d408b02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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