null value in detailview

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?

In your case $model->admin is null… so you need to check for that case too…

Use nullDisplay property:




$this->widget('zii.widgets.CDetailView', array(

    'data'=>$data,

    'attributes'=>array(


    ),

    'nullDisplay'=>'Value is null'

));



or your method, syntax should be




    'value'=>'(!isset($data->admin->name))? "" : $data->admin->name',



  1. ‘name’ property is ignored when you set ‘value’ property.

http://www.yiiframework.com/doc/api/1.1/CDetailView/#attributes-detail

  1. 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',

),