| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 | 
							- <?php
 
- namespace backend\controllers;
 
- use common\models\Carousel;
 
- use common\models\CarouselItem;
 
- use Yii;
 
- use yii\filters\VerbFilter;
 
- use yii\helpers\Url;
 
- use yii\web\Controller;
 
- use yii\web\HttpException;
 
- use yii\web\NotFoundHttpException;
 
- /**
 
-  * CarouselItemController implements the CRUD actions for CarouselItem model.
 
-  */
 
- class CarouselItemController extends Controller
 
- {
 
-     public function getViewPath()
 
-     {
 
-         return $this->module->getViewPath() . DIRECTORY_SEPARATOR . 'carousel/item';
 
-     }
 
-     public function behaviors()
 
-     {
 
-         return [
 
-             'verbs' => [
 
-                 'class' => VerbFilter::className(),
 
-                 'actions' => [
 
-                     'delete' => ['post'],
 
-                 ],
 
-             ],
 
-         ];
 
-     }
 
-     public function actions()
 
-     {
 
-         return [
 
-             'position' => [
 
-                 'class' => 'backend\actions\Position',
 
-                 'returnUrl' => function($model){
 
-                     return Url::to(['/carousel/update', 'id' => $model->carousel_id]);
 
-                 }
 
-             ],
 
-             'switcher' => [
 
-                 'class' => 'backend\widgets\grid\SwitcherAction'
 
-             ]
 
-         ];
 
-     }
 
-     /**
 
-      * Creates a new CarouselItem model.
 
-      * If creation is successful, the browser will be redirected to the 'view' page.
 
-      * @param integer $carousel_id
 
-      * @return mixed
 
-      * @throws HttpException
 
-      */
 
-     public function actionCreate($carousel_id)
 
-     {
 
-         $model = new CarouselItem();
 
-         $carousel = Carousel::findOne($carousel_id);
 
-         if (!$carousel) {
 
-             throw new HttpException(400);
 
-         }
 
-         $model->loadDefaultValues();
 
-         $model->carousel_id =  $carousel->id;
 
-         if ($model->load(Yii::$app->request->post())) {
 
-             if ($model->save()) {
 
-                 Yii::$app->getSession()->setFlash('success', '操作成功');
 
-                 return $this->redirect(['/carousel/update', 'id' => $model->carousel_id]);
 
-             }
 
-         }
 
-         return $this->render('create', [
 
-             'model' => $model,
 
-             'carousel' => $carousel,
 
-         ]);
 
-     }
 
-     /**
 
-      * Updates an existing CarouselItem model.
 
-      * If update is successful, the browser will be redirected to the 'view' page.
 
-      * @param integer $id
 
-      * @return mixed
 
-      */
 
-     public function actionUpdate($id)
 
-     {
 
-         $model = $this->findModel($id);
 
-         if ($model->load(Yii::$app->request->post()) && $model->save()) {
 
-             Yii::$app->getSession()->setFlash('success', '操作成功');
 
-             return $this->redirect(['/carousel/update', 'id' => $model->carousel_id]);
 
-         }
 
-         return $this->render('update', [
 
-             'model' => $model,
 
-         ]);
 
-     }
 
-     /**
 
-      * Deletes an existing CarouselItem model.
 
-      * If deletion is successful, the browser will be redirected to the 'index' page.
 
-      * @param integer $id
 
-      * @return mixed
 
-      */
 
-     public function actionDelete($id)
 
-     {
 
-         $model = $this->findModel($id);
 
-         if ($model->delete()) {
 
-             return $this->redirect(['/carousel/update', 'id'=>$model->carousel_id]);
 
-         };
 
-     }
 
-     /**
 
-      * Finds the CarouselItem model based on its primary key value.
 
-      * If the model is not found, a 404 HTTP exception will be thrown.
 
-      * @param integer $id
 
-      * @return CarouselItem the loaded model
 
-      * @throws NotFoundHttpException if the model cannot be found
 
-      */
 
-     public function findModel($id)
 
-     {
 
-         if (($model = CarouselItem::findOne($id)) !== null) {
 
-             return $model;
 
-         } else {
 
-             throw new NotFoundHttpException('The requested page does not exist.');
 
-         }
 
-     }
 
- }
 
 
  |