Reputation: 2600
I'm trying to use $data->id
on TbButtonColumn
but I'm getting error "Trying to get property of non-object"
.
The TbGridView
is working properly!
What I'm doing wrong?
View.php:
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'type'=>'striped bordered condensed',
'id'=>'profiles-grid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{create}',
'buttons'=>array
(
'create' => array(
'label'=>'Criar Evento',
'icon'=>'plus',
'url'=>'Yii::app()->controller->createUrl("events/create", array("id"=>$data->id))', // Problem here on $data->id
),
),
),
),
)); ?>
Upvotes: 0
Views: 1354
Reputation: 454
Setting the button's url like this worked for me:
'url'=>'$this->grid->controller->createUrl("update", array(
"id"=>$data->primaryKey))',
Upvotes: 2
Reputation: 50602
The error you're getting is caused by the fact that $data
is not an object. You cannot use the property access operator ->
on any other variable type.
It is not clear from your question where $data
is assigned a value, or what that value is supposed to be. You can ensure a variable contains an object using the is_object
function:
if (!is_object($data))
die('There seems to be a problem with the data');
This will tell you that $data
isn't an object, thus preventing the error. BUT, I suspect the underlying problem is whatever mechanism you expect to populate the $data
variable is failing, or not working in the way you expect.
You can use var_dump
to debug variables and check their type in the process:
var_dump($data);
...this will give you a better idea of what $data
actually is -- it isn't an object, that's for sure!
Documentation
is_object
- http://php.net/manual/en/function.is-object.phpvar_dump
- http://php.net/manual/en/function.var-dump.phpUpvotes: 1