Does anyone know how to display a switch/case value in CGridView column field?
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.
I've found this online, but this only apply for 2 values, i need 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
public function getData($data,$row){
switch($data['gender']){
<your codes here to return the result>
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.