I am using an yii dropDownList
for creating a drop-down in my form. I want one value for example '78'=>'selected'
gets default selected in drop-down .My drop down is
dropDownList($testcontroller,'testid',CHtml::listData(Phases::model()->findAllByAttributes(array('pid'=>$pid)), 'id', 'phaseName'));
Can any one help me in doing this
Thanks ;)
dropDownList($testcontroller,
'testid',
CHtml::listData(Phases::model()->findAllByAttributes(array('pid'=>$pid)),
'id',
'phaseName'),
array('options' => array('78'=>array('selected'=>true))));
if its coming from database, use something like below (in case of list box or multiple allowed dropDownList
use 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));
More details about dropDownList : dropDownList() method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With