1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\modules\mailTemplate\controllers; |
4
|
|
|
|
5
|
|
|
use app\modules\user\models\User; |
6
|
|
|
use Yii; |
7
|
|
|
use app\modules\mailTemplate\models\MailTemplate; |
8
|
|
|
use app\modules\mailTemplate\models\SearchMailTemplate; |
9
|
|
|
use yii\filters\AccessControl; |
10
|
|
|
use yii\web\Controller; |
11
|
|
|
use yii\web\NotFoundHttpException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* ManagementController implements the CRUD actions for MailTemplate model. |
15
|
|
|
*/ |
16
|
|
|
class ManagementController extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @inheritdoc |
20
|
|
|
*/ |
21
|
6 |
|
public function behaviors() |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
'access' => [ |
25
|
6 |
|
'class' => AccessControl::className(), |
26
|
|
|
'rules' => [ |
27
|
|
|
[ |
28
|
|
|
'allow' => true, |
29
|
|
|
'actions' => ['index', 'view', 'update'], |
30
|
|
|
'roles' => [User::ROLE_ADMIN], |
31
|
|
|
], |
32
|
|
|
] |
33
|
|
|
] |
34
|
6 |
|
]; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Lists all MailTemplate models. |
39
|
|
|
* |
40
|
|
|
* @return mixed |
41
|
|
|
*/ |
42
|
1 |
View Code Duplication |
public function actionIndex() |
|
|
|
|
43
|
|
|
{ |
44
|
1 |
|
$searchModel = new SearchMailTemplate(); |
45
|
1 |
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
46
|
|
|
|
47
|
1 |
|
return $this->render('index', [ |
48
|
1 |
|
'searchModel' => $searchModel, |
49
|
1 |
|
'dataProvider' => $dataProvider, |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Displays a single MailTemplate model. |
55
|
|
|
* |
56
|
|
|
* @param integer $id |
57
|
|
|
* @return mixed |
58
|
|
|
*/ |
59
|
2 |
|
public function actionView($id) |
60
|
|
|
{ |
61
|
2 |
|
return $this->render('view', [ |
62
|
2 |
|
'model' => $this->findModel($id), |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Updates an existing MailTemplate model. |
68
|
|
|
* If update is successful, the browser will be redirected to the 'view' page. |
69
|
|
|
* |
70
|
|
|
* @param integer $id |
71
|
|
|
* @return mixed |
72
|
|
|
*/ |
73
|
3 |
View Code Duplication |
public function actionUpdate($id) |
|
|
|
|
74
|
|
|
{ |
75
|
3 |
|
$model = $this->findModel($id); |
76
|
|
|
|
77
|
2 |
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
78
|
1 |
|
Yii::$app->getSession()->setFlash('success', Yii::t('mailTemplate', 'Information saved.')); |
|
|
|
|
79
|
1 |
|
return $this->redirect(['view', 'id' => $model->id]); |
80
|
|
|
} |
81
|
2 |
|
return $this->render('update', [ |
82
|
2 |
|
'model' => $model, |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Finds the MailTemplate model based on its primary key value. |
88
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
89
|
|
|
* |
90
|
|
|
* @param integer $id |
91
|
|
|
* @return MailTemplate the loaded model |
92
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
93
|
|
|
*/ |
94
|
4 |
|
protected function findModel($id) |
95
|
|
|
{ |
96
|
4 |
|
$model = MailTemplate::findOne($id); |
97
|
4 |
|
if (null === $model) { |
98
|
1 |
|
throw new NotFoundHttpException('The requested page does not exist.'); |
99
|
|
|
} |
100
|
3 |
|
return $model; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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.