Answer the question
In order to leave comments, you need to log in
Yii2 Display related data in dropDownList?
Hello.
There are 3 tables: Catalog(category), Section(section), Product(product). Section is related to Catalog and Product is related to Section.
All generated through gii. When adding a new Product, I did this:
$form->field($model, 'section_id')->dropDownList(ArrayHelper::map(
Section::find()->all(), 'id_section', 'section_name'
));
Answer the question
In order to leave comments, you need to log in
That's it.
Everything is the same, only the names are different.
See how the catalog is made on the same outlet. There the implementation is as follows:
- Section (for example Computers)
-> ** see below
->Category (for example Monitors, Processors, mice, keyboards)
-> Then the products themselves.
(Optional!) You can also add a sub-category between the section and the category, for example, if you want to separate computers by class (Gaming, laptops, office, etc.) If you have a brand, you can display by brand.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question