condition in view file

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'=&gt;&#036;dataProvider,


'columns'=&gt;array(


	'id',


	'name',


	array(


	'name'=&gt;'phone',


	'type'=&gt;'image',


	[b]'value'=&gt;'if (&#036;data-&gt;phone=0) . &quot;images/red.gif&quot;',[/b]


	),	


	


	


	'email',


       ),

));

?>


'value' => '($data->phone == 0) ? "images/red.gif" : ""',

See here under "Ternary Operator".

I’m sorry but I dont dont understand the meaning of your code.




if ($data->phone=0) . "images/red.gif"'



Minor Typo: You should not have ’ around that expression.


'value' => $data->phone==0 ? 'images/red.gif' : '',

‘value’ => ‘($data->phone == 0) ? “images/red.gif” : “”’,

This is working fine. but I need else $data->phone == 1 then images/green.gif

See here.

Look at the link I posted. You can do this:




'value' => '($data->phone == 0) ? "images/red.gif" : "images/green.gif"',



Ah, of course. Missed that. :)

Thanks. working :rolleyes:

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