CDataColumn 的“值"内的条件语句 [英] conditional statements inside of 'value' for CDataColumn
本文介绍了CDataColumn 的“值"内的条件语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道如何在 CGridView 列字段中显示条件值?
Does anyone know how to display a conditional value in CGridView column field?
我在数据库中有一个条目,用于F"的性别M",在 CGridView 中,但是我想分别显示男"和女",而不是 M 或 F.
I've got an entry in the DB for gender 'M' of 'F', in die CGridView however I would like to display 'Male' and 'Female' respectively and not M or F.
欢迎任何想法;-)
推荐答案
我发现虽然不允许完整的 if/else 语法,但您可以使用速记语法.像这样:
I have found that while full if/else syntax is not allowed, you can use the shorthand syntax. Something like this:
array(
'name'=>'column_name',
'type'=>'HTML',
'value'=>'($data->gender=="M")?"Male":"Female"',
),
我认为您可以使用原始"类型以及HTML"类型来执行此操作.
I think you can do this with the "raw" type, as well as the "HTML" type.
祝你好运!
这篇关于CDataColumn 的“值"内的条件语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文