|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\core\backend; |
|
4
|
|
|
|
|
5
|
|
|
use app\backend\components\BackendController; |
|
6
|
|
|
use app\modules\core\models\Wysiwyg; |
|
7
|
|
|
use yii\filters\AccessControl; |
|
8
|
|
|
use yii\filters\VerbFilter; |
|
9
|
|
|
use Yii; |
|
10
|
|
|
use yii\web\NotFoundHttpException; |
|
11
|
|
|
|
|
12
|
|
|
class WysiwygController extends BackendController |
|
13
|
|
|
{ |
|
14
|
|
|
public function behaviors() |
|
15
|
|
|
{ |
|
16
|
|
|
return [ |
|
17
|
|
|
'access' => [ |
|
18
|
|
|
'class' => AccessControl::className(), |
|
19
|
|
|
'rules' => [ |
|
20
|
|
|
[ |
|
21
|
|
|
'allow' => true, |
|
22
|
|
|
'roles' => ['administrate'], |
|
23
|
|
|
], |
|
24
|
|
|
], |
|
25
|
|
|
], |
|
26
|
|
|
'verbs' => [ |
|
27
|
|
|
'class' => VerbFilter::className(), |
|
28
|
|
|
'actions' => [ |
|
29
|
|
|
'delete' => ['POST'], |
|
30
|
|
|
], |
|
31
|
|
|
], |
|
32
|
|
|
]; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Lists all Wysiwyg models. |
|
38
|
|
|
* @return mixed |
|
39
|
|
|
*/ |
|
40
|
|
View Code Duplication |
public function actionIndex() |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$searchModel = new Wysiwyg(['scenario' => 'search']); |
|
43
|
|
|
$dataProvider = $searchModel->search($_GET); |
|
44
|
|
|
|
|
45
|
|
|
return $this->render('index', [ |
|
46
|
|
|
'dataProvider' => $dataProvider, |
|
47
|
|
|
'searchModel' => $searchModel |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Displays a single Wysiwyg model. |
|
53
|
|
|
* @param integer $id |
|
54
|
|
|
* @return mixed |
|
55
|
|
|
*/ |
|
56
|
|
|
public function actionView($id) |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->render('view', [ |
|
59
|
|
|
'model' => $this->findModel($id), |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Creates a new Wysiwyg model. |
|
65
|
|
|
* If creation is successful, the browser will be redirected to the 'view' page. |
|
66
|
|
|
* @return mixed |
|
67
|
|
|
*/ |
|
68
|
|
|
public function actionCreate() |
|
69
|
|
|
{ |
|
70
|
|
|
$model = new Wysiwyg(); |
|
71
|
|
|
|
|
72
|
|
|
if ($model->load(\Yii::$app->request->post()) && $model->save()) { |
|
73
|
|
|
return $this->redirect(['view', 'id' => $model->id]); |
|
74
|
|
|
} else { |
|
75
|
|
|
return $this->render('create', [ |
|
76
|
|
|
'model' => $model, |
|
77
|
|
|
]); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Updates an existing Wysiwyg model. |
|
83
|
|
|
* If update is successful, the browser will be redirected to the 'view' page. |
|
84
|
|
|
* @param integer $id |
|
85
|
|
|
* @return mixed |
|
86
|
|
|
*/ |
|
87
|
|
|
public function actionUpdate($id, $returnUrl = null) |
|
88
|
|
|
{ |
|
89
|
|
|
$model = $this->findModel($id); |
|
90
|
|
|
|
|
91
|
|
View Code Duplication |
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
|
|
|
|
|
92
|
|
|
if ($returnUrl !== null) { |
|
93
|
|
|
return $this->redirect($returnUrl); |
|
94
|
|
|
} |
|
95
|
|
|
return $this->redirect(['view', 'id' => $model->id]); |
|
96
|
|
|
} else { |
|
97
|
|
|
return $this->render('update', [ |
|
98
|
|
|
'model' => $model, |
|
99
|
|
|
]); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Deletes an existing Wysiwyg model. |
|
105
|
|
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
|
106
|
|
|
* @param integer $id |
|
107
|
|
|
* @return mixed |
|
108
|
|
|
*/ |
|
109
|
|
|
public function actionDelete($id) |
|
110
|
|
|
{ |
|
111
|
|
|
$this->findModel($id)->delete(); |
|
112
|
|
|
|
|
113
|
|
|
return $this->redirect(['index']); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Finds the Wysiwyg model based on its primary key value. |
|
118
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
|
119
|
|
|
* @param integer $id |
|
120
|
|
|
* @return Wysiwyg the loaded model |
|
121
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
|
122
|
|
|
*/ |
|
123
|
|
|
protected function findModel($id) |
|
124
|
|
|
{ |
|
125
|
|
|
if (($model = Wysiwyg::findOne($id)) !== null) { |
|
126
|
|
|
return $model; |
|
127
|
|
|
} else { |
|
128
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
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.