我有dropdown选择在Yii这样的
<?php echo $form->dropdownList($students,'student_name', CHtml::listData(Students::model()->findAll(), 'student_name', 'student_name'), array('selected'=>'Choose One')); ?>
Run Code Online (Sandbox Code Playgroud)
这html output是这样的
<select selected="selected" name="Students[student_name]" id="Students_student_name">
<option value="Alex">Alex</option>
<option value="John">John</option>
<option value="Johny">Johny</option>
<option value="" selected="selected"></option>
</select>
Run Code Online (Sandbox Code Playgroud)
但是我希望Select One应该是default selected value for the dropdown options.So默认情况下会Select One在没有选择任何选项时使用.
[UPDATE]
它正在Select One作为一个选项,当我试图array('prompt'=>'Choose One')和array('empty'=>'Choose One')也.
我认为您使用了错误的键作为默认选择值.
尝试:
// array('prompt'=>'Choose One')
echo $form->dropdownList($students,'student_name', CHtml::listData(Students::model()->findAll(), 'student_name', 'student_name'), array('prompt'=>'Choose One')); ?>
Run Code Online (Sandbox Code Playgroud)