Completed
Push — master ( 2bef99...ca8d01 )
by Andrey
01:41
created

AdminController::beforeAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Itstructure\AdminModule\controllers;
4
5
use Yii;
6
use yii\web\Controller;
7
use Itstructure\AdminModule\Module;
8
use yii\filters\{VerbFilter, AccessControl};
9
10
/**
11
 * Class AdminController
12
 * Default controller for the `admin` module.
13
 *
14
 * @property Module $module
15
 * @property string $urlPrefix Url prefix for redirect and view links.
16
 *
17
 * @package Itstructure\AdminModule\controllers
18
 *
19
 * @author Andrey Girnik <[email protected]>
20
 */
21
class AdminController extends Controller
22
{
23
    /**
24
     * Url prefix for redirect and view links.
25
     * @var string
26
     */
27
    protected $urlPrefix = '';
28
29
    /**
30
     * Initialize.
31
     * @return void
32
     */
33
    public function init()
34
    {
35
        $this->view->params['user'] = Yii::$app->user->identity;
36
    }
37
38
    /**
39
     * @param \yii\base\Action $action
40
     * @return bool
41
     */
42
    public function beforeAction($action)
43
    {
44
        $this->view->params['urlPrefix'] = $this->urlPrefix;
45
46
        return parent::beforeAction($action);
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function behaviors()
53
    {
54
        return [
55
            'access' => [
56
                'class' => AccessControl::class,
57
                'rules' => [
58
                    [
59
                        'allow' => true,
60
                        'roles' => $this->module->accessRoles,
61
                    ],
62
                ],
63
            ],
64
            'verbs' => [
65
                'class' => VerbFilter::class,
66
                'actions' => [
67
                    'delete' => [
68
                        'POST',
69
                    ],
70
                ],
71
            ],
72
        ];
73
    }
74
75
    /**
76
     * Give ability of configure view to the module class.
77
     * @return \yii\base\View|\yii\web\View
78
     */
79
    public function getView()
80
    {
81
        if (method_exists($this->module, 'getView')) {
82
            return $this->module->getView();
83
        }
84
85
        return parent::getView();
86
    }
87
}
88