예제 #1
0
 /**
  * Creates a new Carousel model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Carousel();
     if ($model->load(Yii::$app->request->post())) {
         $model->created_by = Yii::$app->user->identity->username;
         $model->created_date = date('Y-m-d h:m:s');
         $model->modified_by = Yii::$app->user->identity->username;
         $model->modified_date = date('Y-m-d h:m:s');
         $model->status = Status::STATUS_ACTIVE;
         $imageName = substr(md5(rand()), 0, 7);
         if (UploadedFile::getInstance($model, 'file')) {
             $model->file = UploadedFile::getInstance($model, 'file');
             $model->caption = $imageName;
             $model->image_path = 'uploads/carousel/' . $model->file->baseName . $imageName . '.' . $model->file->extension;
         }
         if ($model->save()) {
             $model->file->saveAs('uploads/carousel/' . $model->file->baseName . $imageName . '.' . $model->file->extension);
             Yii::$app->session->setFlash('success', 'Insert Success.');
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             Yii::$app->session->setFlash('error', 'Insert Failed.');
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }