Example #1
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Slider'])) {
         $model->attributes = $_POST['Slider'];
         $uploadedImage = CUploadedFile::getInstance($model, 'imageName');
         //echo'<pre>';print_r($uploadedImage);echo'</pre>';
         if (isset($uploadedImage)) {
             $ephoto = str_replace(' ', '-', "{$uploadedImage->name}");
             $ephoto = 'slider_pic_' . $ephoto;
             $uploadedImage->saveAs(Yii::app()->basepath . '/../images/slider/' . $ephoto);
             $image = Yii::app()->image->load(Yii::app()->basepath . '/../images/slider/' . $ephoto);
             $image->resize(1200, 0);
             $image->save(Yii::app()->basepath . '/../images/slider/1200/' . $ephoto);
             $crop_slider = Slider::cropSlider(Yii::app()->basepath . '/../images/slider/1200/' . $ephoto);
             $imagex = Yii::app()->image->load(Yii::app()->basepath . '/../images/slider/' . $ephoto);
             $imagex->resize(300, 0);
             $imagex->save(Yii::app()->basepath . '/../images/slider/300/' . $ephoto);
             $croped_slider3 = Slider::cropSliderT(Yii::app()->basepath . '/../images/slider/300/' . $ephoto);
             $model->imageName = $ephoto;
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model));
 }