dongluo3331 2013-08-27 22:19
浏览 26
已采纳

使用Yii更改CGridView中参数的值

I a have a basic question about CGridViews. I have the table employees stored in my DB and I am showing some of his atributs using this CGridView. The problem is that I stored all the passwords using the md5 codification, and when I want to show them I don't know how to show them without the md5 codification.

I tried it with the sentence: "'password'=>$dataProvider->employee->md5(password)," But as you can imagine it is wrong and it doesn't work. This is my CGridView with parameter password changed to this sentence.

<?php $this->widget('zii.widgets.grid.CGridView', array(
 'dataProvider'=>$dataProvider,
'id'=>'employee_list',
 'columns'=>array(
    'id',
    'name',
            //'password',
    'password'=>$dataProvider->employee->md5(password),
        array(
        'class'=>'CButtonColumn',
    ),
),
)); ?>

Somebody could help me? Thank you very much.

  • 写回答

2条回答 默认 最新

  • douchun1961 2013-08-28 12:20
    关注

    you just need to pass php code as string, Cgridview will run that string with eval function, Please refer following code for more clarification:

    $this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider'=>$model->search(),
        'columns'=>array(
                array(
                        'name'=>'password',
                        'value'=>'md5($data->password)',
                ),
        ),
    )); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义