コード例 #1
0
 /**
  * Finds the WidgetCarousel model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return WidgetCarousel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = WidgetCarousel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #2
0
 /**
  * Creates a new WidgetCarouselItem model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($carousel_id)
 {
     $model = new WidgetCarouselItem();
     $carousel = WidgetCarousel::findOne($carousel_id);
     if (!$carousel) {
         throw new HttpException(400);
     }
     $model->carousel_id = $carousel->id;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('alert', ['options' => ['class' => 'alert-success'], 'body' => Yii::t('backend', 'Carousel slide was successfully saved')]);
             return $this->redirect(['/widget-carousel/update', 'id' => $model->carousel_id]);
         }
     }
     return $this->render('create', ['model' => $model, 'carousel' => $carousel]);
 }