예제 #1
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())) {
         $model->fileImage = UploadedFile::getInstance($model, 'fileImage');
         if ($model->save()) {
             return $this->redirect(['index']);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } 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(['scenario' => 'create']);
     if ($model->load(Yii::$app->request->getBodyParams())) {
         $file = UploadedFile::getInstance($model, 'image');
         $fileDir = $this->imagePath . DIRECTORY_SEPARATOR;
         $save = $file->saveAs($fileDir . $file->getBaseName() . "." . $file->getExtension());
         if ($save) {
             $model->image = '/slider_images/' . $file->getBaseName() . "." . $file->getExtension();
         }
         if ($model->save()) {
             return $this->redirect(['index']);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #3
0
 public function actionUpdate($id = null)
 {
     $model = new Slider();
     if ($model->load($_POST)) {
         $id = $_POST['Slider']['id'];
         if ($id) {
             $model = Slider::findOne($id);
             $model->attributes = $_POST['Slider'];
         }
         $files = \yii\web\UploadedFile::getInstances($model, 'upload_files');
         if (isset($files) && count($files) > 0) {
             $mPath = $this->getPath();
             foreach ($files as $file) {
                 $mPic = 'nkc_' . substr(number_format(time() * rand(), 0, '', ''), 0, 14) . '.' . $file->extension;
                 //Upload Images
                 if ($file->saveAs($mPath . $mPic)) {
                     //$image = \Yii::$app->image->load($mPath . $mPic);
                     //$image->resize(950, 300);
                     //$image->save($mPath . '/' . $mPic);
                     $model->slider_Url = $this->getUrl() . $mPic;
                 }
             }
         }
         if ($model->save()) {
             $this->updateOrder("langs='" . $model->langs . "' AND cid='" . $model->cid . "' ");
             return $this->redirect(array('index'));
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     if ($id) {
         $model = Slider::findOne($id);
     } else {
         $sess = Yii::$app->session->get('sessSlider');
         $model->langs = $sess['langs'];
     }
     return $this->render('update', ['model' => $model]);
 }