I am writing on the YII2 framework. There is a controller in which there is a code transmitting in view the data that is in the table.

Controller:

public function actionView($id) { // Создаем модель $modelquest = new SQuizQuestion(); // Получаем все вопросы $question = SQuizQuestion::find()->all(); // Формируем массив, с ключем равным полю 'ID_REC' и значением равным полю 'NAME_QUEST' $items = ArrayHelper::map($question,'ID_REC','NAME_QUEST'); return $this->render('view', [ 'modelquest' => $modelquest, 'items' => $items, ]); } 

VIEW:

 <div role="tabpanel" class="tab-pane fade active" id="home"> <div class="row"> <div class="col-lg-5"> <select id="list-assigned" multiple size="20" style="width: 100%"> **ВОТ СЮДА НАДО ИХ ВЫВЕСТИ** </select> </div> </div> </div> 

If I output this way (1):

 <select id="list-assigned" multiple size="20" style="width: 100%"> <?php foreach ($modelquest as $item):?> <option value=""><? echo $item['NAME_QUEST'];?></option> <?php endforeach; ?> </select> 

It turns out that the records are not visible, but you can click on the lines where they should be located.

If I print it like this (2):

 <select id="list-assigned" multiple size="20" style="width: 100%"> <?= Html::activeDropDownList($modelquest, 'ID_REC', $items) ?> </select> 

That records are displayed under the column in which they should be located. Please tell me how to display them in the column so that they are visible and clickable as in the 1st version.

Photos of the 1st and 2nd versions: A photo

    1 answer 1

    Use activeDropDown or dropDown if you don’t need a model:

     <div role="tabpanel" class="tab-pane fade active" id="home"> <div class="row"> <div class="col-lg-5"> <?= Html::activeDropDownList($modelquest, 'ID_REC', $items, ['multiple' => true, 'size' => 20, 'style' => 'width: 100%']) ?> </div> </div> </div> 

    PS Check if you can specify the namespace for HTML , I do not remember exactly which one.

    • Added results to the question, please see - Sanvirtus
    • Did not notice the select tag, updated the answer, check now - Yaroslav Molchan
    • one
      Yes, thank you, everything worked - Sanvirtus