|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\admin\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use yii\filters\VerbFilter; |
|
7
|
|
|
use app\traits\ModelTrait; |
|
8
|
|
|
use app\models\entity\AuthItem; |
|
9
|
|
|
use app\modules\admin\models\forms\AuthItemForm; |
|
10
|
|
|
use app\modules\admin\models\search\AuthItemSearch; |
|
11
|
|
|
|
|
12
|
|
|
class RolesController extends \yii\web\Controller |
|
13
|
|
|
{ |
|
14
|
|
|
use ModelTrait; |
|
15
|
|
|
|
|
16
|
4 |
|
public function behaviors() |
|
17
|
|
|
{ |
|
18
|
|
|
return [ |
|
19
|
4 |
|
'verbs' => [ |
|
20
|
|
|
'class' => VerbFilter::class, |
|
21
|
|
|
'actions' => [ |
|
22
|
|
|
'delete' => ['post'], |
|
23
|
|
|
'batch' => ['post'], |
|
24
|
|
|
], |
|
25
|
|
|
], |
|
26
|
|
|
]; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
4 |
|
public function actions() |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
4 |
|
'batch' => [ |
|
33
|
|
|
'class' => 'app\modules\admin\actions\BatchAction', |
|
34
|
|
|
'modelClass' => 'app\models\entity\AuthItem', |
|
35
|
|
|
'actions' => [ |
|
36
|
|
|
'delete' => [], |
|
37
|
|
|
] |
|
38
|
|
|
], |
|
39
|
|
|
'delete' => [ |
|
40
|
|
|
'class' => 'app\modules\admin\actions\DeleteAction', |
|
41
|
|
|
'modelClass' => 'app\models\entity\AuthItem', |
|
42
|
|
|
], |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
4 |
|
public function actionIndex() |
|
47
|
|
|
{ |
|
48
|
4 |
|
$authItemSearch = new AuthItemSearch(); |
|
49
|
4 |
|
$dataProvider = $authItemSearch->search(Yii::$app->request->get()); |
|
50
|
|
|
|
|
51
|
4 |
|
return $this->render('index', [ |
|
52
|
4 |
|
'authItemSearch' => $authItemSearch, |
|
53
|
4 |
|
'dataProvider' => $dataProvider, |
|
54
|
|
|
]); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
3 |
|
public function actionEdit($name = null) |
|
58
|
|
|
{ |
|
59
|
3 |
|
$model = new AuthItemForm(); |
|
60
|
|
|
|
|
61
|
3 |
|
if ($name) { |
|
62
|
2 |
|
$model->setModel($this->findModel(new AuthItem, $name)); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
2 |
|
if (Yii::$app->request->isPost) { |
|
66
|
|
|
Yii::$app->response->format = 'json'; |
|
67
|
|
|
|
|
68
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
69
|
|
|
$model->save(); |
|
70
|
|
|
|
|
71
|
|
|
Yii::$app->session->setFlash('success', Yii::t('app.msg', 'Saved successfully')); |
|
72
|
|
|
return $this->redirect(['edit', 'name' => $model->name]); |
|
73
|
|
|
} |
|
74
|
|
|
return $this->asJsonModelErrors($model); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
2 |
|
return $this->render('edit', [ |
|
78
|
2 |
|
'model' => $model, |
|
79
|
|
|
]); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
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.