/** * 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) { try { $model = $this->loadModel($id); $model->scenario = 'update'; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $old_image = $model->cover; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Memodule'])) { $model->attributes = $_POST['Memodule']; $isEmptyFileInput = empty($_FILES["Memodule"]["name"]["imageFile"]); if (!$isEmptyFileInput) { //has file input $model->imageFile = CUploadedFile::getInstance($model, 'imageFile'); } $model->status = $_POST['Memodule']['status']; if ($model->validate()) { if (!is_null($model->imageFile)) { $model->cover = Memodule::saveImage($model); Memodule::resizeCover($model); $model->update(array('cover')); } if ($model->update()) { $this->redirect(array('view', 'id' => $model->id)); } } } $this->render('update', array('model' => $model, 'actions' => $this->listActionsCanAccess)); } catch (Exception $e) { Yii::log("Exception " . print_r($e, true), 'error'); throw new CHttpException("Exception " . print_r($e, true)); } }