The problem is in your actionEdit
i.e here
$model->pimg=CUploadedFile::getInstance($model,'pimg');
$fileName=$model->pimg;
$model->attributes=$_POST['Product'];
if($model->save())
$model->pimg->saveAs('images/'.$fileName);
here you should check if the image has been uploaded or not. what happens is that yii is unable to execute this line $model->pimg->saveAs('images/'.$fileName);
as no image has been uploaded. so you need to wrap it inside a condition i.e
if(!empty($model->pimg))
{
$model->pimg->saveAs('images/'.$fileName);
}
so your final code should be something like this
$model->attributes=$_POST['Product'];
$model->pimg=CUploadedFile::getInstance($model,'pimg');
if(!empty($model->pimg))
{
$fileName=$model->pimg->name;
$model->pimg->saveAs('images/'.$fileName);
}
if($model->save())
//render here
Update 1 If you want that on update null should not be stored in your database then you can do this
$model=$this->loadModel($id);
$prevImage=$model->pimg; //add this line
and then where you are using this
if(!empty($model->pimg))
{
$model->pimg->saveAs('images/'.$fileName);
}
else{
$model->pimg=$prevIMage;
}
add this else code