Пример #1
0
 public function actionCreate()
 {
     $model = new Slider();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates a new Slider model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Slider();
     $model->load(Yii::$app->request->post());
     if (Yii::$app->request->isPost) {
         if ($model->validate() && $model->save()) {
             $this->saveImages($model);
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('update', ['model' => $model]);
 }
Пример #3
0
 /**
  * Creates a new Slider model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Slider();
     $model->active = 1;
     if ($model->load(Yii::$app->request->post())) {
         $image = Upload::uploadImage($model);
         if ($model->save()) {
             // upload only if valid uploaded file instance found
             if ($image !== false) {
                 $path = Upload::getImageFile($image);
                 $image->saveAs($path);
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Slider model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Slider();
     if ($model->load(Yii::$app->request->post())) {
         $file = UploadedFile::getInstances($model, 'image');
         $model->image = $file[0];
         if (sizeof($file) > 0) {
             $image_name = '/sliders/' . $model->image->baseName . '_' . time() . '.' . $model->image->extension;
             $image_path = Yii::getAlias('@frontend') . '/web/uploads' . $image_name;
             $model->image->saveAs($image_path);
             $model->image = $image_name;
             $model->save();
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #5
0
 /**
  * Creates a new Slider model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Slider();
     if ($model->load(Yii::$app->request->post())) {
         if (isset($_FILES) && $_FILES) {
             $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
             if ($model->imageFile) {
                 $model->upload();
             }
         }
         if ($model->ord == "") {
             $model->ord = 0;
         }
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }