I had a difficulty: when updating, the user must download the file again, the old one will be deleted, and the new name will be written into the database.
But to change any information you have to re-upload the file, which is quite inconvenient.
In the model there is a mandatory file download:
array('filename', 'file', 'types'=>'rar, zip, 7z','allowEmpty'=>false,'maxFiles' => 1,'message'=>'Допустимые типы к загрузке: rar, zip, 7z'), How to make that if the file is not selected, then the file recording would not be made, and vice versa, respectively?
Update (controller code):
$model=$this->loadModel($id); $model->scenario='update'; if(isset($_POST['ModsManage'])) { $set_info = ModsManage::model()->findByPk($id); $model->attributes=$_POST['ModsManage']; if(CUploadedFile::getInstance($model,'filename')){ $model->filename = CUploadedFile::getInstance($model,'filename'); }else{ $model->filename = $set_info->filename; } if($model->save()){ if(CUploadedFile::getInstance($model,'filename')){ if(file_exists(Yii::getPathOfAlias('webroot').'/mods/'.$model->id.'/'.$set_info->filename)){ unlink(Yii::getPathOfAlias('webroot').'/mods/'.$model->id.'/'.$set_info->filename); } $path=Yii::getPathOfAlias('webroot').'/mods/'.$model->id.'/'.$model->filename->getName(); $model->filename->saveAs($path); } //$this->redirect(array('mod','id'=>$model->id)); } } $this->render('update',array( 'model'=>$model, ));