conditional statements inside of 'value' for CDataColumn

时光毁灭记忆、已成空白 提交于 2019-12-20 03:32:33

问题


Does anyone know how to display a conditional value in CGridView column field?

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.

Any ideas would be welcome ;-)


回答1:


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"',
),

I think you can do this with the "raw" type, as well as the "HTML" type.

Good luck!



来源:https://stackoverflow.com/questions/3873022/conditional-statements-inside-of-value-for-cdatacolumn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!