1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\modules\admin\controllers; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\filters\VerbFilter; |
7
|
|
|
use yii\helpers\Url; |
8
|
|
|
use app\traits\ModelTrait; |
9
|
|
|
use app\models\AuthItem; |
10
|
|
|
use app\modules\admin\models\forms\AuthItemForm; |
11
|
|
|
use app\modules\admin\models\search\AuthItemSearch; |
12
|
|
|
|
13
|
|
|
class RolesController extends \yii\web\Controller |
14
|
|
|
{ |
15
|
|
|
use ModelTrait; |
16
|
|
|
|
17
|
4 |
|
public function behaviors() |
18
|
|
|
{ |
19
|
|
|
return [ |
20
|
4 |
|
'verbs' => [ |
21
|
|
|
'class' => VerbFilter::class, |
22
|
|
|
'actions' => [ |
23
|
|
|
'delete' => ['post'], |
24
|
|
|
'operations' => ['post'], |
25
|
|
|
], |
26
|
|
|
], |
27
|
|
|
]; |
28
|
|
|
} |
29
|
|
|
|
30
|
4 |
|
public function actions() |
31
|
|
|
{ |
32
|
|
|
return [ |
33
|
4 |
|
'operations' => [ |
34
|
|
|
'class' => 'app\modules\admin\controllers\common\OperationsAction', |
35
|
|
|
'modelClass' => 'app\models\AuthItem', |
36
|
|
|
'operations' => [ |
37
|
|
|
'delete' => [], |
38
|
|
|
] |
39
|
|
|
], |
40
|
|
|
'delete' => [ |
41
|
|
|
'class' => 'app\modules\admin\controllers\common\DeleteAction', |
42
|
|
|
'modelClass' => 'app\models\AuthItem', |
43
|
|
|
], |
44
|
|
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
4 |
|
public function actionIndex() |
48
|
|
|
{ |
49
|
4 |
|
$authItemSearch = new AuthItemSearch(); |
50
|
4 |
|
$dataProvider = $authItemSearch->search(Yii::$app->request->get()); |
51
|
|
|
|
52
|
4 |
|
return $this->render('index', [ |
53
|
4 |
|
'authItemSearch' => $authItemSearch, |
54
|
4 |
|
'dataProvider' => $dataProvider, |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
public function actionEdit($name = null) |
59
|
|
|
{ |
60
|
3 |
|
$model = new AuthItemForm(); |
61
|
|
|
|
62
|
3 |
|
if ($name) { |
63
|
2 |
|
$model->setModel($this->findModel(new AuthItem, $name)); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
if (Yii::$app->request->isPost) { |
67
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
68
|
|
|
try { |
69
|
|
|
$model->save(); |
70
|
|
|
|
71
|
|
|
Yii::$app->session->setFlash('success', Yii::t('app.msg', 'Saved successfully')); |
72
|
|
|
return $this->asJson(['redirect' => Url::toRoute(['edit', 'name' => $model->name])]); |
73
|
|
|
} catch (\Exception $e) { |
74
|
|
|
Yii::error($e); |
75
|
|
|
return $this->asJson(false); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
return $this->asJson($this->collectErrors($model)); |
79
|
|
|
} |
80
|
|
|
|
81
|
2 |
|
return $this->render('edit', [ |
82
|
2 |
|
'model' => $model, |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.