F
F
freshik3122019-07-30 17:55:19
Yii
freshik312, 2019-07-30 17:55:19

How to correctly implement data transfer in gridview yii2?

Good afternoon !
Help solve the problem ..
Essence: there is a grid of goods that are compared by the user. Each cook receives an "attributes" model, in which I write the product name and attribute data [ 'высота' => '100', 'цвет' => 'зеленый' ].
Those. I get data like this:

[
[0] => [
    'name' => 'Test name',
    'price' => 300,
    ...
    'attributes' => [
            'color' => 'green',
            'width' => 100,
        ]
    ],
[1] => [
    'name' => 'primer prod',
    'price' => 100,
    ...
    'attributes' => [
            'color' => 'yellow'
        ]
    ]
]

Considering that the admin will create and delete attributes, I cannot set the necessary columns (columns) in advance.
How can I add columns with a name and value obtained from attributes, and if there is no attribute (as 'primer prod' does not have 'width') - put "no data" in the value?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-07-30
@freshik312

'attributes' => array_map(function (Value $value) {
    return [
        'label' => $value->characteristic->name,
        'value' => $value->value,
    ];
}, $product->values),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question