T
T
Tokenchik2017-05-26 17:00:16
Yii
Tokenchik, 2017-05-26 17:00:16

How to get drop down from related table?

In the forms generated by gii, you need to add a dropDownList into which data from the table linked via hasOne will enter. How to do it right? I found so far just creating a field as a separate widget, how else can I do it, but please at least with an example.
UPD:
So far done like this:

<?= $form->field($model, 'state_id')->dropDownList(\yii\helpers\ArrayHelper::map(\app\modules\admin\models\State::find()->all(), 'id', 'state')) ?>

Please tell me is it true or not?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-05-26
@Tokenchik

Good afternoon.
Can be done with dropDownList() Like
this:

<?= $form->field($model, 'region_id')->dropDownList(ArrayHelper::map(Regions::getAllName(), 'id', 'name_ru')); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question