I have a form where the user is able to see the list of vendor to create a new Application,
The problem is that the Vendor is Optional, it means in my dropdown list, i would like to show an empty field that automatically generates en empty value of the VENDOR_ID but yii tells "Trying to get property of non-object"
<?php echo$form->dropDownList(//dropDownList with an empty array for 0,1->0,n relations
$model,'VENDOR_ID', CHtml::listData(
Vendor::model()->findAll(),'VENDOR_ID','NAME'
),
array(
'empty' =>'<no Solder>',
)
);?>
I think i understand the problem, the empty value i create is not of type $model->Vendor that’s why i get an error message, but i don’t know how to solve it.
Put your Vendor::model().->findAll() into a method of your Vendor model and call this method in the view. In this method check the result of the query and return an empty array if result is empty, otherwise the ActiveRecord elements…