Hi just wondering if no new image upload, will the record get updated without losing the existing data in DB?
Currently my code belows if no image upload…the record updated with erase exiting image path in db. Please assist.
public function actionUpdate($id)
{
$model=$this->loadModel($id);
if(isset($_POST['Promotions']))
{
$model->attributes=$_POST['Promotions'];
$basePath = Yii::getPathOfAlias('webroot');
$image = CUploadedFile::getInstance($model, 'image_1');
if (isset($image) && !is_null($image)) {
$filename = uniqid('', true).'.'.strtolower($image->extensionName); //uniqid('', true) . $image1;
$model->image_1 = (!is_null($image)) ? '/images/promotions/' . $filename : '';
}
if($model->save()){
if (isset($image) && !is_null($image)) {
$image->saveAs($basePath. $model->image_1);
}
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('update',array(
'model'=>$model,
));
}