DropDownList

I got a very simple question now.

I have a basic array of record types:

$recordType = array(‘type 1’, ‘type 2’…‘type n’);

I need to use it in a form as a DropDown:

$form->DropDownList($model,‘type’,$recordType);

this seam to work, except for 2 things:

  • I need value field to be an index to the array. YII seam to put array element

    in both value and text

  • I have no idea how to control default selected entry.

I know I am supposed to use listData or something but I am not sure how to specify array index

as an element value in select tag.

Do I HAVE to convert this 5 element array to the model and store it in db in order to have it

in drop down? I hope not!

thank you.

create the array like that:




$recordType = array(0=>'type 1', 1=> 'type 2' n=>'type n');



for explain the couple id=>value.

The default selected entry is the value of the model, so if you do “$model->type=1” it will select, in this example, ‘type 2’.

thanks! this looks like its working.