Reputation: 401
In the view I have a such code
<?= $form->field($model, 'Language')->dropDownList(ArrayHelper::map(Doodles::getLanguages(), "Language", "language"), ['class'=>'form-control','prompt' => 'Choose language'])->label('Language') ?>
In the Doodles::getLanguages
method
return Doodles::findBySql('select distinct language from doodles')->asArray()->all();
And getLanguages
method returns
array (size=2)
0 => array (size=1) 'language' => string 'rus' (length=3) 1 => array (size=1) 'language' => string 'en' (length=2)
In result page I got a select with not filled value attributes and with only one option instead two
<select id="utdoodles-language" class="form-control" name="UtDoodles[Language]">
<option value="">Choose language</option>
<option value="" selected="">en</option>
</select>
Addition:
Doodles::getLanguages method return an array:
array (size=2) 0 => array (size=1) 'language' => string 'rus' (length=3) 1 => array (size=1) 'language' => string 'en' (length=2)
Upvotes: 0
Views: 38
Reputation: 5731
In the Doodles::getLanguages
method change as below :
return Doodles::find()->select('language')->distinct()->asArray()->all();
Upvotes: 1