77use yii \web \Controller ;
88use yii \web \NotFoundHttpException ;
99use yii \filters \VerbFilter ;
10- use yii2mod \cms \models \search \CmsModelSearch ;
1110use yii2mod \editable \EditableAction ;
1211use yii2mod \toggle \actions \ToggleAction ;
1312
1817class CmsController extends Controller
1918{
2019 /**
21- * @var string view path
20+ * @var string path to index view file, which is used in admin panel
2221 */
23- public $ viewPath = '@vendor/yii2mod/yii2-cms/views/cms/ ' ;
22+ public $ indexView = '@vendor/yii2mod/yii2-cms/views/cms/index ' ;
23+
24+ /**
25+ * @var string path to create view file, which is used in admin panel
26+ */
27+ public $ createView = '@vendor/yii2mod/yii2-cms/views/cms/create ' ;
28+
29+ /**
30+ * @var string path to update view file, which is used in admin panel
31+ */
32+ public $ updateView = '@vendor/yii2mod/yii2-cms/views/cms/update ' ;
33+
34+ /**
35+ * @var string search class name for searching
36+ */
37+ public $ searchClass = 'yii2mod\cms\models\search\CmsSearch ' ;
38+
39+ /**
40+ * @var string model class name for CRUD operations
41+ */
42+ public $ modelClass = 'yii2mod\cms\models\CmsModel ' ;
2443
2544 /**
2645 * @inheritdoc
@@ -60,41 +79,45 @@ public function actions()
6079
6180 /**
6281 * Lists all CmsModel models.
82+ *
6383 * @return mixed
6484 */
6585 public function actionIndex ()
6686 {
67- $ searchModel = new CmsModelSearch ( );
87+ $ searchModel = Yii:: createObject ( $ this -> searchClass );
6888 $ dataProvider = $ searchModel ->search (Yii::$ app ->request ->queryParams );
6989
70- return $ this ->render ($ this ->viewPath . ' index ' , [
90+ return $ this ->render ($ this ->indexView , [
7191 'dataProvider ' => $ dataProvider ,
7292 'searchModel ' => $ searchModel
7393 ]);
7494 }
7595
7696 /**
7797 * Creates a new CmsModel model.
78- * If creation is successful, the browser will be redirected to the 'view' page.
98+ *
99+ * If creation is successful, the browser will be redirected to the 'index' page.
100+ *
79101 * @return mixed
80102 */
81103 public function actionCreate ()
82104 {
83- $ model = new CmsModel ( );
105+ $ model = Yii:: createObject ( $ this -> modelClass );
84106
85107 if ($ model ->load (Yii::$ app ->request ->post ()) && $ model ->save ()) {
86108 Yii::$ app ->session ->setFlash ('success ' , Yii::t ('yii2mod.cms ' , 'Page has been created. ' ));
87109 return $ this ->redirect (['index ' ]);
88110 }
89111
90- return $ this ->render ($ this ->viewPath . ' create ' , [
91- 'model ' => $ model,
112+ return $ this ->render ($ this ->createView , [
113+ 'model ' => $ model
92114 ]);
93115 }
94116
95117 /**
96118 * Updates an existing CmsModel model.
97- * If update is successful, the browser will be redirected to the 'view' page.
119+ *
120+ * If update is successful, the browser will be redirected to the 'index' page.
98121 *
99122 * @param integer $id
100123 *
@@ -108,13 +131,15 @@ public function actionUpdate($id)
108131 Yii::$ app ->session ->setFlash ('success ' , Yii::t ('yii2mod.cms ' , 'Page has been updated. ' ));
109132 return $ this ->redirect (['index ' ]);
110133 }
111- return $ this ->render ($ this ->viewPath . 'update ' , [
112- 'model ' => $ model ,
134+
135+ return $ this ->render ($ this ->updateView , [
136+ 'model ' => $ model
113137 ]);
114138 }
115139
116140 /**
117141 * Deletes an existing CmsModel model.
142+ *
118143 * If deletion is successful, the browser will be redirected to the 'index' page.
119144 *
120145 * @param integer $id
@@ -135,15 +160,17 @@ public function actionDelete($id)
135160 * @param integer $id
136161 *
137162 * @return CmsModel the loaded model
163+ *
138164 * @throws NotFoundHttpException if the model cannot be found
139165 */
140166 protected function findModel ($ id )
141167 {
142- if (($ model = CmsModel::findOne ($ id )) !== null ) {
168+ $ cmsModel = $ this ->modelClass ;
169+
170+ if (($ model = $ cmsModel ::findOne ($ id )) !== null ) {
143171 return $ model ;
144172 } else {
145173 throw new NotFoundHttpException (Yii::t ('yii2mod.cms ' , 'The requested page does not exist. ' ));
146174 }
147175 }
148-
149- }
176+ }
0 commit comments