GridView Column Problem


I getting error “Trying to get property of non-object” when accessing the $data->srvbytes. When I declare as $data[‘srvdata’] it works. Why is that so? FYI, my data source is from ArrayDataProvider. Thanks.

GridView::widget([‘dataProvider’ => $dataprovider,

‘columns’ => [ [‘attribute’ => ‘srvbytes’,‘label’ => ‘Server Bytes’, ‘format’ => ‘raw’,

‘value’ => function($data){ return $data->srvbytes’];}]);

Try this "


										'attribute' => 'average_laundry_price',


												return "$".$data->average_laundry_price;




The dataprovider is coming from ArrayDataProvider.

Not working. Still with the same error message

It is wrong the definition of DataColumn of GridView (value property):$value-detail

Expressing the value via array method works.

GridView::widget(['dataProvider' => $dataprovider,

 'columns' => [ ['attribute' => 'srvbytes','label' => 'Server Bytes', 'format' => 'raw', 

 'value' => function($data){ return $data['srvbytes']];}]); 

If it works is because the first parameter of ‘value’ callable function is the model.

If you read the documentation, the function signature is:

function ($model, $key, $index, $column)

Ok, What I was confused about, is that when the dataprovider was from SQL the reference to the ‘value’ would be $data->srvbytes whereas in my case the dataprovider came from an ArrayDataProvider. The confusing part for me is the inconsistent way to access the ‘value’ across dataprovider.