zoukankan      html  css  js  c++  java
  • 关于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"])'),

  • 相关阅读:
    Java实体书写规范
    Mybatis配置中遇到的问题和问题分析
    Ubuntu下eclipse的Extjs提示插件安装
    Ubuntu中root用户和user用户的相互切换
    ubuntu下启动和关闭tomcat的简单方法
    Ubuntu上安装Maven Eclipse以及配置
    IE8兼容<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    心情
    更改Eclipse下Tomcat的部署目录
    Tomcat:IOException while loading persisted sessions: java.io.EOFException 解决
  • 原文地址:https://www.cnblogs.com/jicheng1014/p/2770850.html
Copyright © 2011-2022 走看看