Hi all,
the problem is if i want to update the other fields and not the image … it passes the validation and doesn’t update any of the fields .
But if i upadte the image and other fields it updates.
or
if i upadte the image it updates.
view
[code]
<?php echo $form->labelEx($model,'pimg'); ?>
<?php echo $form->fileField($model, 'pimg',array('id'=>'imgInput',)); ?>
<?php echo $form->error($model,'pimg'); ?>
controller
public function actionEdit($id)
{
$model=$this->loadModel($id);
if(isset($_POST['Product']))
{
$model->pimg=CUploadedFile::getInstance($model,'pimg'); $fileName=$model->pimg;
$model->attributes=$_POST['Product'];
if($model->save())
$model->pimg->saveAs('images/'.$fileName);
$this->redirect(array('display','id'=>$model->productid));
}
$this->render('edit',array('model'=>$model,));
}
model rules
array('name, category, model, brand, description, price', 'required'),
array('pimg', 'file','types'=>'jpg','on'=>'create', 'allowEmpty'=>false),
array('pimg', 'file','types'=>'jpg','on'=>'update', 'allowEmpty'=>true),
[code]
I think the problem is with the contorller i keep getting the error
Fatal error: Call to a member function saveAs() on a non-object in D:\wamp\www\testfolder\protected\controllers\ProductController.php on line 147
line 147 $model->pimg->saveAs(‘images/’.$fileName);
image appears but then image name from db doesn’t appear next to the choose file button renders stating no file choosen
PLEASE HELP!
I am new to Yii and am loosing my mind on this. Thank you.