Yii Dropdown-Liste einen Leeren Wert als Standard

Ich habe eine dropdownlist in meinem _form Modell und möchte ich hinzufügen, dass ein leerer Wert (wich ich möchte als default). Ich habe Folgendes:
In _form:

<?php echo $form->labelEx($model,'country_id'); ?>
<?php echo $form->dropDownList($model,'country_id',Country::items(),array('empty' => '--Select a country--')); ?>
<?php echo $form->error($model,'country_id'); ?>

Im Modell-Land:

public static function items()
{
    return CHtml::listData(Country::model()->findAllBySql(
                        'SELECT * from country'), 
                        'id', 'name');
}

Sogar meine leere option ist in der ersten Zeile in der dropdownlist, das 1. Land in der Liste zeigt standardmäßig.

Habe ich versucht:

<?php echo $form->dropDownList($model,'country_id',
    Country::items(),array('empty'=>'--Select a country--',
                           'options'=>
                             array(
                               '3'=>array('selected'=>'selected')
                                 )
     )); 
?>

In dieser Art kann ich wählen Sie die option "Standard", kann aber nicht legen Sie es auf einen leeren Wert, nur Länder, die kam von der Modell:Artikel.

Irgendeine Idee?

InformationsquelleAutor coppettim | 2013-04-17
Schreibe einen Kommentar