Hi all, a small question from beginner.
I need to attach icon to product, I did pic uploads following instructions:
http://www.yiiframew…doc/cookbook/2/
all works fine, but i need to set icon-field NOT REQUIRED, I dont need to reupload pic on each row update.
There's a rules from Model.
public function rules()
{
return array(
array('name','length','max'=>255),
array('icon', 'file', 'types'=>'jpg, gif, png'),
array('name, price1, price2, is_published', 'required'),
array('is_published, category_id', 'numerical', 'integerOnly'=>true),
array('price1, price2', 'numerical'),
);
}
A part from Controller
public function actionUpdate()
{
$product=$this->loadProduct();
if(isset($_POST['Product']))
{
$product->attributes=$_POST['Product'];
$product->icon=CUploadedFile::getInstance($product, 'icon');
if($product->save())
{
$product->icon->saveAs('uploads/'.$product->icon->getName());
$this->redirect(array('show','id'=>$product->id));
}
}
$this->render('update',array('product'=>$product));
}
Icon field not marked as required by red *, but on form save i got validation error:
Please fix the following input errors:
- Icon cannot be blank.
Where I'm was wrong?
Thanks!