简体   繁体   English

在CDataColumn的“值”内切换大小写

[英]Switch case inside of 'value' for CDataColumn

Does anyone know how to display a switch/case value in CGridView column field? 有谁知道如何在CGridView列字段中显示开关/案例值?

I've got an entry in the DB for types 'Picture', 'Video', 'Audio', 'Drawing', in the CGridView however I would like to display the Text instead of 1, 2, 3, 4. 我在CGridView的DB中有一个类型为“图片”,“视频”,“音频”,“绘图”的条目,但是我想显示Text而不是1、2、3、4。

I've found this online, but this only apply for 2 values, i need 4, 我在网上找到了这个,但这仅适用于2个值,我需要4个

array(
  'name'=>'column_name',
  'type'=>'HTML',
  'value'=>'($data->gender=="1")?"Male":"Female"',
),

Any ideas would be great! 任何想法都很棒!

array(
  'name'=>'column_name',
  'type'=>'HTML',
  'value'=>function($data){
      $result = 'unknown';
      //($data->gender=="1")?"Male":"Female"
      switch($data->gender)
     {
       case 'male':
       $result = 'this was male';
       break;
     }
     return $result;
   },
),

You can call a function to determine the value. 您可以调用一个函数来确定值。

'value'=>array($this,'getData')

In your controllor, create a function named getData 在您的控件中,创建一个名为getData的函数

public function getData($data,$row){
 switch($data['gender']){
  <your codes here to return the result>
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM