我使用yii dropDownList在我的表单中创建下拉列表.我想要一个值例如'78'=>'selected'在下拉列表中选择默认值.我的下拉列表是
dropDownList($testcontroller,'testid',CHtml::listData(Phases::model()->findAllByAttributes(array('pid'=>$pid)), 'id', 'phaseName'));
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我这样做
谢谢 ;)
aru*_*run 20
dropDownList($testcontroller,
'testid',
CHtml::listData(Phases::model()->findAllByAttributes(array('pid'=>$pid)),
'id',
'phaseName'),
array('options' => array('78'=>array('selected'=>true))));
Run Code Online (Sandbox Code Playgroud)
如果它来自数据库,请使用类似下面的内容(如果是列表框或多个允许dropDownList使用multiple=>true)
foreach ($selections as $eachValue)
$selectedOptions[$eachValue] = array('selected'=>'selected');
echo $form->dropDownList($model,
'testid',
CHtml::listData(Phases::model()->findAllByAttributes(array('pid'=>$pid)),
'id',
'phaseName'),
array('multiple'=>'true','prompt'=>'select ','options'=>$selectedOptions));
Run Code Online (Sandbox Code Playgroud)
有关dropDownList的更多详细信息:dropDownList()方法