teguh11
(Teguhkrstianto)
1
i have problem with CDetailView.
when i write like this
array(
'name'=>'name',
'value'=>$model->admin->name ==null ? "" : $data->admin->name,
'label'=>'Approve By',
),
i got a error.
Trying to get property of non-object
in my database, name admin is null.
can someone resolve that?
mdomba
(Maurizio Domba Cerin)
2
In your case $model->admin is null… so you need to check for that case too…
Byakuya
(Vsevolodr)
3
Use nullDisplay property:
$this->widget('zii.widgets.CDetailView', array(
'data'=>$data,
'attributes'=>array(
),
'nullDisplay'=>'Value is null'
));
rootbear
(Alex Xm)
4
or your method, syntax should be
'value'=>'(!isset($data->admin->name))? "" : $data->admin->name',
softark
(Softark)
5
- ‘name’ property is ignored when you set ‘value’ property.
http://www.yiiframework.com/doc/api/1.1/CDetailView/#attributes-detail
- As mdomba has pointed out, you should check if $model->admin is not null.
array(
'value'=>isset($model->admin) ? $model->admin->name : "",
'label'=>'Approve By',
),
Or,
array(
'value'=>(isset($model->admin) && isset($model->admin->name)) ? $model->admin->name : "",
'label'=>'Approve By',
),