Alberk
(Alberk)
December 22, 2015, 5:59am
1
Hi,
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’];}]);
sukunj
(Mendparasukunj27)
December 22, 2015, 6:19am
2
Hi,
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',
'content'=>function($data){
return "$".$data->average_laundry_price;
}
],
Alberk
(Alberk)
December 22, 2015, 6:38am
3
Hi,
The dataprovider is coming from ArrayDataProvider.
Not working. Still with the same error message
Alberk
(Alberk)
December 22, 2015, 10:30am
5
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)
Alberk
(Alberk)
December 23, 2015, 12:38am
7
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.