/**
  * 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)
 {
     $this->__baseScriptUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../assets');
     Yii::app()->getClientScript()->registerCssFile($this->__baseScriptUrl . '/news.css');
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['NewsCategory'])) {
         $model->current_parent = $model->parent_id;
         $model->attributes = $_POST['NewsCategory'];
         $model->parent_id = $_POST['NewsCategory']['parent_id'];
         $fileUpload = CUploadedFile::getInstance($model, 'image');
         if (isset($fileUpload) && $model->validate()) {
             $uploadPath = YiiBase::getPathOfAlias('webroot') . '/files/news';
             //Yii::app()->basePath . '/../jlwebroot/upload';
             if (!is_dir($uploadPath)) {
                 @mkdir($uploadPath);
                 @chmod($uploadPath, 0777);
             }
             // Delete old image
             if ($model->image) {
                 @unlink($uploadPath . '/' . $model->image);
                 @unlink($uploadPath . '/thumb_' . $model->image);
             }
             $filename = time() . mt_rand(0, 0xfff) . '.' . $fileUpload->getExtensionName();
             $fileUpload->saveAs($uploadPath . '/' . $filename);
             /**
              * @todo chưa có setting cho thumbnail                 
              * */
             // thumbnails image
             $thumbsPath = $uploadPath;
             Yii::import('ext.phpthumb.EasyPhpThumb');
             $thumbs = new EasyPhpThumb();
             $thumbs->init();
             $thumbs->setThumbsDirectory($thumbsPath);
             $thumbs->load($uploadPath . '/' . $filename)->resize(80, 60)->save('thumb_' . $filename);
             $model->image = $filename;
         }
         if ($model->validate() && $model->removeImage && $model->image) {
             // Delete old image
             if ($model->image) {
                 @unlink($uploadPath . '/' . $model->image);
                 @unlink($uploadPath . '/thumb_' . $model->image);
             }
             $model->image = '';
         }
         $model->modified = date('Y-m-d H:i:s', time());
         if ($model->saveNode()) {
             $this->redirect(array('admin'));
         }
     }
     $arrTrees = NewsCategory::model()->roots()->findAll();
     $this->render('form', array('model' => $model, 'arrTrees' => $arrTrees));
 }
Exemple #2
0
 public function actionTestResize()
 {
     $file = Yii::getPathOfAlias('webroot.p.6000') . "/4932925_1_l.JPG";
     Yii::import('ext.phpthumb.EasyPhpThumb');
     $thumbs = new EasyPhpThumb();
     echo 'ok';
     $thumbs->init();
     $thumbs->setThumbsDirectory('/p/3000');
     $thumbs->load($file)->resize(Photo::$sizes['full'][0], Photo::$sizes['full'][1])->save('4932925_1_l.JPG', "JPG")->resize(Photo::$sizes['small'][0], Photo::$sizes['small'][1])->save('4932925_1_l_.JPG', "JPG");
     echo ' ok';
 }