I have a situation in updating the record without replacing the file path in Yii. Whatever I do, it always empty my file path field in database. here is my code in controller
if(isset($_POST['Band']))
{
$model->attributes = $_POST['Band'];
$myfile = CUploadedFile::getInstance($model,'logo');
if($model->save())
{
if(!empty($myfile))
{
$path = explode(".", $myfile->name);
$filePath = 'files/'.$myfile->name;
$myfile->saveAs($filePath);
}
$this->redirect(array('view','id'=>$model->band_id));
}
}
This is what I've done so far but still the logo filed in database updates to null.
Try this code, it's for you -
In model rules array define this -