drop-down-menuyiiselectedyii-chtml

yii -> dropDownList -> CHtml::listData -> set selected value


How can I set the selected value in the following statement:

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

I want to set in the list:

iso = AT
landname = Österreich

as selected value.

EDITED -> The solution:

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)),
    )
);

Solution

  • this works..

    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)),
        )
    );