Problem with selected value and dropDownList of an enum.


I am encountering a strange bug while trying to make a form field in order to edit a MySQL ENUM field.

I am currently creating the field like this :


echo $form->labelEx($model,'role');

echo $form->dropDownList($model,'role', array('user', 'client', 'admin'));

echo $form->error($model,'role');


As you can see, I’ve got a column named role which can be set to user, client or admin.

Then problem is that the dropdown list doesn’t select the current role (I checked $model and it is correctly assigned).

After trying a few things, I think them problem comes from the line 1879 of CHtml.php ( where $key is a number and my default value, $selection is a string so strcmp always returns -1.

If I replace $key with $value, the problem disappears.

I don’t know if this is a real bug or if I’m just using the wrong approach to set the default value with this control.

Can somebody enlighten me about this issue?

Thanks a lot,


try with


Thanks, I’ll learn to read the documentation correctly from now on -__-

Read documentation and code. I found that often is easier to read code, it is already documented very good, and if something is not documented good, you can always check code directly.

Yep I did it this time but maybe I was a bit too sleepy… Thanks for the tip, I’ll do it awake next time !