0

I am pretty sure that there is a better way to populate the array, needed for the dropdown:

<?php 

$items2 = [Yii::$app->user->identity->id => Yii::$app->user->identity->username ]; ?>
<!--...some html -->

<?= $form->field($model, 'idUser')->dropDownList($items2,['Item' => ''])?>

already try:

$item2 = ArrayHelper::map(Yii::$app->user->identity::find()->all(), 'id', 'name');

reason, I want to display 'name' but submit 'value'='id'.

crlshn
  • 87
  • 8
  • Possible duplicate of [How to make a drop down list in yii2?](http://stackoverflow.com/questions/21569053/how-to-make-a-drop-down-list-in-yii2) – Jørgen Mar 28 '16 at 07:09

1 Answers1

1

Should be this

<?= $form->field($model, 'idUser')->
        dropDownList(ArrayHelper::map(Yii::$app->user->identity->find()->all(),
      'id', 'username'), ['prompt'=>'Select...'])?>
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • $items2 = ArrayHelper::map(Yii::$app->user->identity, 'id', 'name'); die($items2); returns "Array", not the values that i need. $items2 = [ '0' => 'crlshn' ] – crlshn Mar 27 '16 at 21:06
  • I have update the answer and checked for dektrium user now return the dropdown with the username and assign the id – ScaisEdge Mar 28 '16 at 06:15