|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\backend\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use dmstr\helpers\Metadata; |
|
6
|
|
|
use Yii; |
|
7
|
|
|
use yii\data\ArrayDataProvider; |
|
8
|
|
|
use yii\filters\AccessControl; |
|
9
|
|
|
use yii\web\Controller; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Default backend controller. |
|
13
|
|
|
* |
|
14
|
|
|
* Usually renders a customized dashboard for logged in users |
|
15
|
|
|
*/ |
|
16
|
|
|
class DefaultController extends Controller |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
View Code Duplication |
public function behaviors() |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
return [ |
|
24
|
|
|
'access' => [ |
|
25
|
|
|
'class' => AccessControl::className(), |
|
26
|
|
|
'rules' => [ |
|
27
|
|
|
[ |
|
28
|
|
|
'allow' => true, |
|
29
|
|
|
'actions' => ['error'], |
|
30
|
|
|
], |
|
31
|
|
|
[ |
|
32
|
|
|
'allow' => true, |
|
33
|
|
|
'matchCallback' => function ($rule, $action) { |
|
34
|
|
|
return \Yii::$app->user->can( |
|
35
|
|
|
$this->module->id.'_'.$this->id.'_'.$action->id, |
|
36
|
|
|
['route' => true] |
|
37
|
|
|
); |
|
38
|
|
|
}, |
|
39
|
|
|
], |
|
40
|
|
|
], |
|
41
|
|
|
], |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Actions defined in classes, eg. error page. |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function actions() |
|
51
|
|
|
{ |
|
52
|
|
|
return [ |
|
53
|
|
|
'error' => [ |
|
54
|
|
|
'class' => 'yii\web\ErrorAction', |
|
55
|
|
|
], |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Application dashboard. |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
|
|
public function actionIndex() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->render('index'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Application configuration. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function actionViewConfig() |
|
75
|
|
|
{ |
|
76
|
|
|
$loadedModules = Metadata::getModules(); |
|
77
|
|
|
$loadedModulesDataProvider = new ArrayDataProvider(['allModels' => $loadedModules]); |
|
78
|
|
|
|
|
79
|
|
|
return $this->render( |
|
80
|
|
|
'view-config', |
|
81
|
|
|
[ |
|
82
|
|
|
'params' => Yii::$app->params, |
|
83
|
|
|
'components' => Yii::$app->getComponents(), |
|
84
|
|
|
'modules' => Yii::$app->getModules(), |
|
85
|
|
|
'loadedModulesDataProvider' => $loadedModulesDataProvider, |
|
86
|
|
|
] |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.