Dropdownlist Optgroup In Formbuilder

Hello everyone!

I need your help, I am using the multimodelform extension to allow user pick many items (models) with their properties and then save them in models.

The problem I am having now is that I show a combobox and everything is fine, but dont know how to make a combobox with categories (as OPTGROUPS)

in the widget properties:

'formConfig' => $examen->getMultiModelForm(), //the form configuration array


public function getMultiModelForm()


$listaExamenes = Examen::getListExamen();

return array(





                                'prompt'=>'Seleccione un exámen',






//		  		'value'=>0,





public static function getListExamen() {

                $examenes = Examen::model()->findAll(array('order'=>'nombre', 'condition'=>'t.activo = 1'));

                return CHtml::listData($examenes,'id','nombre');


I have two db tables

‘examen’ which contains all clickable items, and it has a foreign key ‘examen_tipo_id’ which refers to the table that categorize the items.


table examen (id, name, foreign_key)

1 - item1 - 1

2 - item2 - 1

3 - item3 - 2

table examen_tipo (id, name)

1 - cat1

2 - cat2

Then, I want the combobox like


  • item1

  • item2


  • item3

I have seen examples in a form, but how to do it in a formbuilder mode?

thanks in advanced!

Dear Friend

We can construct the dropDownList in the following way.

$form->dropDownList($model,'name',CHtml::listData(Item::model()->findAll(),'id','name','brand.name')); //brand.name is going to group the items.

Here model Item has a realtion with model [b]Brand/b;


Thanks for your response.

The problem is that the formbuilder (‘items’=>$listdata,) doesnt have $form, and in the method I am building it (getMultiModelForm) dont have $model

I dont know which $model type of object is (Item?)