Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditional statements inside of 'value' for CDataColumn

Tags:

php

yii

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 ;-)

like image 261
Conrad Avatar asked Dec 05 '25 20:12

Conrad


1 Answers

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!

like image 130
thaddeusmt Avatar answered Dec 08 '25 12:12

thaddeusmt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!