neel
(Kazi Neel)
1
Hello,
I need a condition in my view file but don’t understand how to do that
this is my view file
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
'name',
array(
'name'=>'phone',
'type'=>'image',
[b]'value'=>'if ($data->phone=0) . "images/red.gif"',[/b]
),
'email',
),
));
?>
Y11
(Y!!)
2
'value' => '($data->phone == 0) ? "images/red.gif" : ""',
See here under "Ternary Operator".
yiimann
(Contact)
3
I’m sorry but I dont dont understand the meaning of your code.
if ($data->phone=0) . "images/red.gif"'
mikl
(Mike)
4
Minor Typo: You should not have ’ around that expression.
'value' => $data->phone==0 ? 'images/red.gif' : '',
neel
(Kazi Neel)
5
‘value’ => ‘($data->phone == 0) ? “images/red.gif” : “”’,
This is working fine. but I need else $data->phone == 1 then images/green.gif
Y11
(Y!!)
7
Look at the link I posted. You can do this:
'value' => '($data->phone == 0) ? "images/red.gif" : "images/green.gif"',
mikl
(Mike)
8
Ah, of course. Missed that. 
Just a note, when writing a ternary, it’s generally good practice to wrap the entire ternary in parens to avoid issues.
( ($data->phone == 0) ? "images/red.gif" : "images/green.gif" )