1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace andmemasin\language\controllers; |
4
|
|
|
|
5
|
|
|
use andmemasin\language\Module; |
6
|
|
|
use yii; |
7
|
|
|
use andmemasin\language\models\Language; |
8
|
|
|
use andmemasin\language\models\LanguageSearch; |
9
|
|
|
use yii\web\Controller; |
10
|
|
|
use yii\web\NotFoundHttpException; |
11
|
|
|
use yii\web\ForbiddenHttpException; |
12
|
|
|
use yii\filters\VerbFilter; |
13
|
|
|
use yii\filters\AccessControl; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* LanguageController implements the CRUD actions for Language model. |
17
|
|
|
*/ |
18
|
|
|
class LanguageController extends Controller |
19
|
|
|
{ |
20
|
|
|
/** @var Module */ |
21
|
|
|
public $module; |
22
|
|
|
|
23
|
|
|
public function init() |
24
|
|
|
{ |
25
|
|
|
$this->module = \Yii::$app->getModule('language'); |
26
|
|
|
parent::init(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function behaviors() |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
return [ |
36
|
|
|
'access' => [ |
37
|
|
|
'class' => AccessControl::class, |
38
|
|
|
'rules' => [ |
39
|
|
|
[ |
40
|
|
|
'allow' => true, |
41
|
|
|
'roles' => [$this->module->permissionMap['admin']], |
42
|
|
|
], |
43
|
|
|
], |
44
|
|
|
], |
45
|
|
|
|
46
|
|
|
'verbs' => [ |
47
|
|
|
'class' => VerbFilter::class, |
48
|
|
|
'actions' => [ |
49
|
|
|
'delete' => ['POST'], |
50
|
|
|
], |
51
|
|
|
], |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Lists all Language models. |
58
|
|
|
* @return mixed |
59
|
|
|
* @throws ForbiddenHttpException |
60
|
|
|
*/ |
61
|
|
|
public function actionIndex() |
62
|
|
|
{ |
63
|
|
|
|
64
|
|
|
$searchModel = new LanguageSearch(); |
65
|
|
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
66
|
|
|
|
67
|
|
|
return $this->render('index', [ |
68
|
|
|
'searchModel' => $searchModel, |
69
|
|
|
'dataProvider' => $dataProvider, |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Displays a single Language model. |
75
|
|
|
* @param string $id |
76
|
|
|
* @return mixed |
77
|
|
|
* @throws ForbiddenHttpException |
78
|
|
|
* @throws NotFoundHttpException |
79
|
|
|
*/ |
80
|
|
|
public function actionView($id) |
81
|
|
|
{ |
82
|
|
|
return $this->render('view', [ |
83
|
|
|
'model' => $this->findModel($id), |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Creates a new Language model. |
89
|
|
|
* If creation is successful, the browser will be redirected to the 'view' page. |
90
|
|
|
* @return mixed |
91
|
|
|
* @throws ForbiddenHttpException |
92
|
|
|
*/ |
93
|
|
|
public function actionCreate() |
94
|
|
|
{ |
95
|
|
|
$model = new Language(); |
96
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
97
|
|
|
return $this->redirect(['view', 'language_id' => $model->primaryKey]); |
98
|
|
|
} else { |
99
|
|
|
return $this->render('create', [ |
100
|
|
|
'model' => $model, |
101
|
|
|
]); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Updates an existing Language model. |
107
|
|
|
* If update is successful, the browser will be redirected to the 'view' page. |
108
|
|
|
* @param string $id |
109
|
|
|
* @return mixed |
110
|
|
|
* @throws ForbiddenHttpException |
111
|
|
|
* @throws NotFoundHttpException |
112
|
|
|
*/ |
113
|
|
|
public function actionUpdate($id) |
114
|
|
|
{ |
115
|
|
|
|
116
|
|
|
$model = $this->findModel($id); |
117
|
|
|
|
118
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
119
|
|
|
return $this->redirect(['view', 'language_id' => $model->primaryKey]); |
120
|
|
|
} else { |
121
|
|
|
return $this->render('update', [ |
122
|
|
|
'model' => $model, |
123
|
|
|
]); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Deletes an existing Language model. |
129
|
|
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
130
|
|
|
* @param string $id |
131
|
|
|
* @return mixed |
132
|
|
|
* @throws ForbiddenHttpException |
133
|
|
|
* @throws NotFoundHttpException |
134
|
|
|
*/ |
135
|
|
|
public function actionDelete($id) |
136
|
|
|
{ |
137
|
|
|
$this->findModel($id)->delete(); |
138
|
|
|
return $this->redirect(['index']); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Finds the Language model based on its primary key value. |
143
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
144
|
|
|
* @param string $id |
145
|
|
|
* @return Language the loaded model |
146
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
147
|
|
|
*/ |
148
|
|
|
protected function findModel($id) |
149
|
|
|
{ |
150
|
|
|
if (($model = Language::findOne((int) $id)) !== null) { |
151
|
|
|
return $model; |
152
|
|
|
} else { |
153
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|