D
D
Denis2021-08-21 17:21:56
Yii
Denis, 2021-08-21 17:21:56

Outputting value in Yii2 dropDownList from related tables?

Good day to all! Please help.
There is a table to which an entry is made:
--client_equipment
--->client_lk_id
In the client_lk_id field, an id from the table is passed:
--client_lk
--->id
--->client_id
--->name_lk_id
In turn, an id from tables:
--client
--->id
--->clien_name
id from the table is passed to name_lk_id:
--name_lk
--->id
--->name

In other words, there are clients, each client can have a personal account (and more than one), and equipment is connected to the personal account (also several). Clients are created, personal accounts are attached to them. We create equipment and link it to a personal account.

The question is how, when creating equipment , to display in dropDownList instead of name_lk_id / client_id the value of client_name / name from another table

<?= $form
->field($model, 'client_lk_id')
->dropDownList(
\yii\helpers\ArrayHelper::map(common\models\ClientLk::find()->all(), 'id', 'name_lk_id', 'client_id')
); ?>

so now:
1
-2
-3
2
-1
and you need it like this:
client Ivanov
-personal office1
-personal office2
client Petrov
-personal office1
I'm sorry for such gibberish!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question