There is a news editing page. I update the record in this way:
$model=News::model()->findByPk($_GET['id']); if(isset($_POST['News'])) { $model->attributes=$_POST['News']; $model->save(); } All is good, only I have a field that contains an image. If I leave an empty file selection form, then the value of this field will overwrite with an empty string. How can I prevent the update of this field if I do not select the file, those leave the old image?
rulesmodel has a string of typearray('img', 'file','types'=>'jpg, gif, png', 'allowEmpty'=>true, 'on'=>'update'),,? That is, resolves the unloaded photos during the update - Alexey Shimansky$model = $this->loadModel($id); $old_img = $model->img; $model->img = ''; if(isset($_POST['News'])) { $model->attributes = $_POST['News']; if(empty($model->img)) $model->img = $old_img; $model->save(); }$model = $this->loadModel($id); $old_img = $model->img; $model->img = ''; if(isset($_POST['News'])) { $model->attributes = $_POST['News']; if(empty($model->img)) $model->img = $old_img; $model->save(); }try it like this - Alexey Shimanskyif(isset($_POST['News'])) { if ($_POST['News']['image']=='') unset($_POST['News']['image']); $model->attributes=$_POST['News']; if($model->save()) {...............} }if(isset($_POST['News'])) { if ($_POST['News']['image']=='') unset($_POST['News']['image']); $model->attributes=$_POST['News']; if($model->save()) {...............} }if(isset($_POST['News'])) { if ($_POST['News']['image']=='') unset($_POST['News']['image']); $model->attributes=$_POST['News']; if($model->save()) {...............} }- Alexey Shimansky