/** * 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); $fileModel = new FileUploadFormModel(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $this->layout = '//layouts/admin'; if (isset($_POST['Event'])) { $transaction = Yii::app()->db->beginTransaction(); try { $model->attributes = $_POST['Event']; if ($model->save()) { $fileModel->LoadUploadedeImage(); $fileModel->setScenario(FileUploadFormModel::FILE_UPLOAD_MODE_SINGLE); if ($fileModel->isUploadedFile()) { if ($fileModel->validate()) { $ips = new ImageProcessService($fileModel, get_class($model), $model->id, "icon"); $ips->saveImage(300, 300); $SavedFileRelativePaths = $ips->getOriginalImageVirtualPath(); $SavedThumbnailFileRelativePaths = $ips->getThumbnailImageVirtualPath(); $model->save_img_src($SavedFileRelativePaths, $SavedThumbnailFileRelativePaths); $transaction->commit(); $this->redirect(array('view', 'id' => $model->id)); } } else { $transaction->commit(); $this->redirect(array('view', 'id' => $model->id)); } } } catch (Exception $ex) { $transaction->rollback(); Yii::app()->user->setFlash(FlashMsg::ERROR, $e->getMessage()); } } $this->render('create', array('model' => $model, 'fileModel' => $fileModel)); }
public function actionCreateIllust($mode) { /* validate all query string param */ $model = new Illust('create'); $model->categorize($mode); //this will throw new CHttpException(404,'test'); /*define the required variable for the controller base on the query string param */ $fileModel = new FileUploadFormModel(); $view; $scen; if ($model->Illust_cat_title == Illust::ILLUST_CAT_TITLE) { $scen = FileUploadFormModel::FILE_UPLOAD_MODE_SINGLE; $view = 'createIllust'; } else { $scen = FileUploadFormModel::FILE_UPLOAD_MODE_MULTI; $view = 'createManga'; } if (isset($_POST['Illust'])) { $model->setAttributes($_POST['Illust']); //$fileHandler->LoadUploadedeImageToModel(); //$model->photos = $fileHandler->photos; //$model->photos = CUploadedFile::getInstancesByName(BSMultiFileUploadWidget::fieldName); if ($model->validate()) { $fileModel->LoadUploadedeImage(); $fileModel->setScenario($scen); if ($fileModel->validate()) { if ($model->save()) { $ips = new ImageProcessService($fileModel, get_class($model), Yii::app()->user->user_name, $model->id); $ips->saveImage(150, 150); $SavedFileRelativePaths = $ips->getOriginalImageVirtualPath(); $SavedThumbnailFileRelativePaths = $ips->getThumbnailImageVirtualPath(); //$SavedFileRelativePaths = $fileModel->processImage(get_class($model),Yii::app()->user->user_name,$model->id); $model->save_img_src($SavedFileRelativePaths, $SavedThumbnailFileRelativePaths); $model->addOwnerUserId(Yii::app()->user->id); Yii::app()->user->setFlash(FlashMsg::SUCCESS, "投稿作品成功"); $this->redirect(SeoHelper::illustViewSEORouteArray($model)); } else { Yii::app()->user->setFlash(FlashMsg::ERROR, "投稿作品失敗"); } } } } $this->render($view, array('model' => $model, 'fileModel' => $fileModel)); }