dropDownList and default select

Hi everyone,

I’m sorry for my english:) I have problem with a dropDownList and default value.

When I use this code:

<?php echo CHtml::dropDownList('name', '0', array('0'=>'value1', '1'=>'value2'));

For this example dafault value is ‘value1’. It’s ok but when I want to use dropDownList and $model I can’t to select default value. See this code, please.

<?php echo CHtml::dropDownList($model, 'attrubuteName, $data)); ?>

I don’t know where to give a default value. Has anyone any idea? Is it possible?


If you want to use the dropDownList with model, you should set the default value in either controller or model class


//inside the controller's action function

$model->name = 0;


//in the model class declaration

$name = 0;

You don’t have to do that. :)

I think this would work:

<?php echo CHtml::dropDownList('name', '0', array('0'=>'value1', '1'=>'value2'),

 array('options' => array('1'=>array('selected'=>true)))); ?>

Isn’t he want to use the model method??

Thanks everyone!

It’s ok:



                	<?php echo $form->dropDownList($model, 'issue_priority_id', CHtml::listData(

                	IssuePriority::model()->findAll(array('order'=>'id')), 'id', 'name'), array('options' => array('2'=>array('selected'=>true)))); ?>

Cool! I used the same topic when I wanted to figure out how to do that.:lol:

But any is there any different comparing with setting default values to the model instead??

jacmoe, u r a life saver. Thank you very much.