A
A
Anton2014-10-19 17:49:38
Yii
Anton, 2014-10-19 17:49:38

How to display a list with categories from the database when creating a record in Yii2?

Hello!
It's some kind of bastard. Either I'm not catching up with something, or their guide is terrible at the current stage. No specific examples.
I will describe the essence of what I do. Created CRUD categories. Create, edit, view and delete their plows. But when creating, you need to select the parent category for the category being created, if necessary.
I collected something in pieces, but everything was by - Errors only managed to catch. Well, it is not possible to add a drop-down list with created categories when creating a new category.
Please, help. Write a ready-made example, otherwise I don’t know what to do anymore ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2014-10-19
@hummingbird

We take all categories from the database, make an array, display dropDownList

$categories = app\models\Category::findAll();
$data = yii\helpers\ArrayHelper::map($categories, 'id', 'name');
$form->field($model, 'parent_id')->dropDownList($data);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question