/** * 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); $status_path_atual = $model->status_path; $modelP = new Itens(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Status'])) { $model->attributes = $_POST['Status']; if (!CUploadedFile::getInstance($model, 'status_path')) { $model->status_path = $status_path_atual; } if ($model->save()) { $model2 = Status::model()->findByPk($model->status_id); if (isset($_POST['Status']) && !empty($_FILES['Status']['name']['status_path'])) { $model->status_path = CUploadedFile::getInstance($model, 'status_path'); $nm = md5(date("Ymd h:i:s")) . rand(5, 15) . "." . $modelP->extensionImg($model->status_path->type); $caminho = Yii::app()->params['uploadPath'] . DIRECTORY_SEPARATOR . Yii::app()->params['uploadPathStatus']; if (!is_dir($caminho . $model->status_id)) { mkdir($caminho . $model->status_id); } $model->status_id = $model2->status_id; $model->status_path->saveAs($caminho . $model->status_id . DIRECTORY_SEPARATOR . $nm, true); $model->status_path = $nm; $model->save(); } $this->redirect(array('admin')); } } $this->render('update', array('model' => $model)); }