Yii Dropdown List Empty Value as Default
Read documentation. There is 'prompt' parameter.
Try this:
<?php
echo $form->dropDownList($model,'country_id',Country::items(), array(
'prompt' => '--Select a country--'
));
?>
See more details here http://www.yiiframework.com/forum/index.php/topic/11195-how-to-edit-the-default-option-in-dropdownlist/
Are you sure that country_id
property of your model is not set to anything when you print the dropdown list? The following works for me if $model
instance is created using new Country()
operator but not by populating properties from database:
<?php echo $form->dropDownList(
$model,
'country_id',
Country::items(),
array(
'empty'=>'--Select a country--')
);
?>