Search code examples
phpyiiconditional-statementscgridview

Condition statement in value attr CGridView Yii


when I do this in CgridView:

'value' => '$data->status == 1 ? "Payed" : "None" ',

it works, but when I do this:

'value' => 'if ($data->status == 1) { echo "Payed"; } else if($data->status == 2) { echo "Two"; } else { echo "None"; } '.

What I need to do to make work the second statement, or how I need to rewrite it?


Solution

  • Convert your statement to use ternary if:

    'value' => '$data->status == 1 ? "Payed": ($data->status == 2 ? "Two" : "None")',