I try like this, but it’s not the same as defining DropDownList statically(Look at my attachments,please). DropDown_IS will show, as it is ,actually, DropDown_Soll will show, as it should be. The sequence of values is unimportant!
To create these for my drop downs I use a model method. Let’s say I want the keys to be the id’s and the values to be some other model attribute.
//view of form
<?= $form->field($model, 'attribute')->dropDownList($model->getDropDownArray()); ?>
//in the model
public function getDropDownArray()
{
$modelname = Modelname::find()
->where(['someattribute'=>$somevariable]) //optional if conditions needed to limit data
->all();
$items = array();
foreach($modelname as $model){
$items[$model->id] = $model->attribute
}
return $items;
}
This way the keys of the array $items are the ids and the values of the array are all the user sees.