/** * 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['anli'])) { $model->attributes = $_POST['anli']; $anli = anli::model()->findByPk($id); $img = $_FILES['anli']['name']['image']; if ($img !== '') { $img = CUploadedFile::getInstance($model, 'image'); $extensionName = explode('.', $img->getName()); $extensionName = $extensionName[count($extensionName) - 1]; $day_file = date('Y-m-d', time()); $path = dirname(Yii::app()->basePath) . '/upload/case'; CommonFunction::do_mkdir($day_file, $path); $time_path = date('Y', time()) . '/' . date('m', time()) . '/' . date('d', time()) . '-'; $dir = dirname(Yii::app()->basePath) . '/upload/case/' . $time_path; $img_src = $dir . md5(time()) . '.' . $extensionName; $img1 = md5(time()) . '.' . $extensionName; $model->image = $time_path . $img1; } else { $model->image = $anli->image; } //$model->cate_id = $_POST['Caigou']['cate_id']; if ($model->save()) { if ($img !== '') { @unlink(dirname(Yii::app()->basePath) . '/upload/case/' . $anli->image); //$model->default_image->saveAs(dirname(Yii::app()->basePath) .'/upload/caigou/'.$pic_name,true); $img->saveAs($img_src); } $this->redirect(array('/admin/case/admin')); } } $this->render('update', array('model' => $model)); }