V
V
Vyacheslav2016-11-19 05:45:53
MySQL
Vyacheslav, 2016-11-19 05:45:53

How to display a field through Grid yii2?

Hello,
Please tell me how to display the value field from the array using GridView::widget:
Thanks in advance.

[2] => Array
        (
            [country_id] => 336
            [cities_count] => 0
            [i18n] => Array
                (
                    [0] => Array
                        (
                            [language] => ru
                            [object_type] => country
                            [object_id] => 336
                            [object_field] => name
                            [value] => Китай
                            [value_text] => 
                        )
                )
        )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav, 2016-11-19
@exe90

'columns' => [
                 [
                     'attribute' => 'Название страны',
                     'content' => function(array $model) {
                         return $model['i18n'][0]['value'];
                     }
                 ],
            ],

It turned out to be deduced only in this way, tell me how correct this entry is? Or what is the best way to write?

I
Ilya, 2016-11-19
@rpsv

Do you mean this:

GridView::widget([
    'dataProvider' => $arrayDataProvider,
    'columns' => [
        // ...
        [
            'attribute' => 'i18n',
            'content' => function(array $model) {
                return $model['value'];
            }
        ],
        // ...
    ]
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question