AccessControl.php
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace backend\components\filters;
use Yii;
use yii\helpers\ArrayHelper;
use yii\web\ForbiddenHttpException;
/**
*
* @author wuxiao
* @date 2016-8-19
*/
class AccessControl extends \yii\filters\AccessControl
{
/**
* @var array a list of access rule objects or configuration arrays for creating the rule objects.
* If a rule is specified via a configuration array, it will be merged with [[ruleConfig]] first
* before it is used for creating the rule object.
* @see ruleConfig
*/
public $rules = [
[
'allow' => true,
'roles' => ['@'],
],
];
public function init()
{
$rules = [];
$this->rules = ArrayHelper::merge($rules, $this->rules);
$this->denyCallback = function ($rule, $action) {
if (Yii::$app->user->getIsGuest()) {
Yii::$app->user->loginRequired();
} else {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
}
};
parent::init();
}
public function beforeAction($action)
{
return parent::beforeAction($action);
}
}