How can I get the value and not the key from dropDownList Yii2

yii\widgets\ActiveField\dropDownList() in Yii2 usually returns the key in pare ['key' => 'value'] from the selection. How can I get the value?

+5
source share
1 answer

Use the same values ​​for key and value

in this sampling country there is a code and a name, and mao gives you key value

  $listData=ArrayHelper::map($countries,'code','name'); 

in this example

  $listData=ArrayHelper::map($countries,'name','name'); 

enter value, value

 echo $form->field($model, 'name')->dropDownList($listData, ['prompt'=>'Choose...']); 
+5
source

Source: https://habr.com/ru/post/1238725/


All Articles