Answer the question
In order to leave comments, you need to log in
How to display data from a table using dropdown?
There is such a structure of the subcategory table: id, category_id, name (that is, the ID, to which ID of the category the name of the subcategory belongs).
How can I get the list from the database like this?
i.e. a grouped list: category first, below it subcategories related to it.
Answer the question
In order to leave comments, you need to log in
Good evening.
You need to collect a multidimensional array, which you can pass to dropDownList().
It looks like this:
$form->field($model, 'status')->dropDownList(
[
'Активный' => ['Админ', 'Модератор', 'Пользователь'],
'Отключён' => ['За нарушения', 'Самостоятельно']
],
[
'prompt' => 'Выбрать статус'
])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question