N
N
Nikolai Novosad2015-11-26 23:57:25
Yii
Nikolai Novosad, 2015-11-26 23:57:25

Yii2 Dropdown list when creating a new post in admin?

Hello.
I have tables: catalog(Laptop), partition(Asus), product(ASUS X553MA-XX490D). The section is associated with the catalog and the product is associated with the section. Through CRUD, everything was generated and working.
But how to make it so that when you create a new record in the product in the Catalog_id field there is a drop-down list with sections (Asus, Lenovo, HP)? Or even take a value from a directory like Laptop->Samsung or Monitor->Samsung. It's just that the database lacks the same firms of different products.
Now, in the Catalog_id text field, you need to enter a number that corresponds to the id_product of the Product table.
It is clear that you need to pull a query from the database with a value and a key, and display it through select, but how to implement this in Yii2?
Can someone explain what and where to write?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-11-27
@nik_neman

in a view

<?= $form->field($model, 'Catalog_id')->dropDownList(
        ArrayHelper::map(Notebook::find()->all(), 'id', 'namePC'),
        ['prompt'=>'Выберите значание']
    );

well, something like this approximately .. just substitute your data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question