Answer the question
In order to leave comments, you need to log in
How to set default value in yii2 dropdownlist?
<?=
$form->field($model, 'id_shop')->dropDownList(ArrayHelper::map(User::find()
->selectUser()
->all(),
'id', 'name'))->label(false) ?>
Answer the question
In order to leave comments, you need to log in
Here is a simple example.
$form->field($mod, 'testDrop')->dropDownList([0 => '1', 1 => '2', 2 => '3'], [
'options' => [
1 => ['selected' => true] // Меняя цифру можно установить какой-либо элемент массива по умолчанию
]
]);
$form->field($model, 'id_shop')->dropDownList(ArrayHelper::map(/*********/), [
'options' => [
2 => ['selected' => true] // Если, конечно, такой id есть в базе
]
]);
via promt or if you need something special
<?php
$a=Categories::find()->select(['name', 'id'])->indexBy('id')->orderBy('name ')->column();
$a[0]='';
echo $form->field($model, 'parent_id')->dropdownList(
$a,
[
'options' => [
'0' => ['selected' => true]
]
]
)->label('Parent category'); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question