N
N
Nikolai Novosad2016-06-13 01:56:12
Yii
Nikolai Novosad, 2016-06-13 01:56:12

Yii2 Display related data in admin?

Hello.
I am using advanced template. There is related data. In the form (_form.php) when adding, I use this code to display not id, but normal data.

<?= $form->field($model, 'team_id')->label('Сборная')->dropDownList(
        ArrayHelper::map(Team::find()->all(), 'id_team', 'team'),
        ['prompt' => 'Выберите игрока']
    ); ?>

But when you view all the information, the id appears. Where and how to change so that text information from the linked table appears instead of ID?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Arutyunov, 2016-06-13
@arutyunov

Try, for example, this extension: https://github.com/kartik-v/yii2-widget-select2
It is very convenient to work with related data.

M
Maxim Timofeev, 2016-06-14
@webinar

1. Your code is not a link. The relationship is described in the model and has hasOne or hasMany
2.

But when you look at all the information
Where are you browsing? What is the information provided with?
3. чтобы вместо ID появлялась текстовая информация
$model->relationName->someAttribute

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question