关于Yii 中使用CArrayDataProvider的CGridview 没有办法去自定义列的显示的问题

ok,我们用惯了系统的CActiveDataProvider作为CGridview的数据源  

我们知道平时我们要是去自定义一个列的时候可以在CGridview 下的columns 里指定其某个column 的value

例如

    'columns'=>array(
        'id',
        'hostname',
        'chinese_name',
        'probe_type',
        'last_responsible_ip',
                array('name'=>'last_response_time',
                    'value'=>'date("Y-m-d H:i:j",$data->last_response_time)'),
        'area.name',
        array(
            'class'=>'bootstrap.widgets.TbButtonColumn',
        ),
    ),

但是如果我们在使用CArrayDataProvider作为数据源的时候,类似'value'=>'date("Y-m-d H:i:j",$data->last_response_time)'), 这种写法是会报错的。

 

Trying to get property of non-object

D:\xampp\htdocs\yiiRoot\framework\base\CComponent.php(607) : eval()'d code(1)

image

这个地方的原因是因为我们传递的实际上是数组,而不是以前的对象了   我们只需要把对象换成数组使用就可以了  比如说这里

'value'=>'date("Y-m-d H:i:j",$data->last_response_time)'), 换成'value'=>'date("Y-m-d H:i:j",$data["last_response_time"])'),

posted @ 2012-11-15 00:56  Atpking  阅读(626)  评论(0编辑  收藏  举报