A
A
AlexSer2021-05-13 10:35:21
Yii
AlexSer, 2021-05-13 10:35:21

How to access columns in Gridview in Yii2 ArrayDataProvider?

I display data through Gridview + ArrayDataProvider.
How can I access the string value?

'columns'=>[
               [
                       'label'=>$title,
                        'attribute'=>'ubg',
                        'value'=>function($model){
},
               ]
        ],

Through function($model) does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin, 2021-05-13
@kot999

what means does not work, you do not return anything from the method?
what does it mean to refer to columns? render fields?
then in columns you can simply list the names of the fields

columns=>[
'id', 
'name', 
'email'
]

for more complex logic, each field can be described by an array
'columns' => [
            [
                'label' => $title,
                'attribute' => 'name',
                'value' => function ($model) {
                    return $model['name'] . $model['surname'];
                },
            ],
            'age',
        ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question