yii - > dropDownList - > CHtml :: listData - >设置选定的值

时间:2013-11-12 20:01:56

标签: drop-down-menu yii selected yii-chtml

如何在以下语句中设置所选值:

echo $form->dropDownList(
    $model,
    'land_id',
    CHtml::listData(ListeLand::model()->findAll(), 'iso', 'landname'),
    array('class'=>'span4 chosen','maxlength'=>20)
);

我想在列表中设置:

iso = AT
landname = Österreich

作为选定值。

已编辑 - >解决方案:

echo $form->dropDownList(
    $model,
    'land_id',
    CHtml::listData(ListeLand::model()->findAll(), 'iso', 'landname'),
    array(
                'class'=>'span4 chosen',
                'maxlength'=>20,
                'options' => array('AT'=>array('selected'=>true)),
    )
);

1 个答案:

答案 0 :(得分:3)

这有效..

echo $form->dropDownList(
    $model,
    'land_id',
    CHtml::listData(ListeLand::model()->findAll(), 'iso', 'landname'),
    array(
                'class'=>'span4 chosen',
                'maxlength'=>20,
                'options' => array('AT'=>array('selected'=>true)),
    )
);
相关问题