Manipulating Data for the CGridView

I am having a bit of trouble manipulating the data before displaying it in the CGridView.

I’ve got this code for the other columns which works great:

$this->widget(‘zii.widgets.grid.CGridView’, array(




array(‘type’=>‘html’,‘name’ => ‘rooms’,‘value’=> ‘"<div align=\“center\”>" .CHtml::encode($data->rooms). “</div>”’)



But the problem comes in when I want to check if the value is equal to 0 then change the data accordingly. For instance, here is my php code:

($data->price == ‘0’) ? $data->price = ‘Contact Us for pricing information’: $data->price = ‘$’ . number_format($data->price, 0);

How do I perform this if statement before displaying the data?

Your expression needs to return a value that will be displayed… so… just do not assign the value to the variable… like

$data->price=='0' ? 'Contact Us for pricing information' : '$'.number_format($data->price,0);

But the issue is using that in context of the

columns =>array( value=>


What is the issue?

This should work



   'value'=>'$data->price=="1" ? "Contact Us for pricing information" : "$".number_format($data->price,0)',


Note: in this example the expression should be enclosed with single quotes as we want that $data->price is evaluated at runtime…

Well, I guess there isn’t. It works now. Thanks a lot.

When I was doing it last night the value would either be ‘Contact Us for pricing’ for all of them or all would show price and so some said $0. This framework is awesome by the way, just have to learn the lingo.

what if I want to compare 3 values ? like


    case Benda::TIPE_FOOD:

	return Benda::TIPE_FOOD_STR;

    case Benda::TIPE_SAUCE:

	return Benda::TIPE_SAUCE_STR;

    case Benda::TIPE_VEG:

	return Benda::TIPE_VEG_STR;


What kind of expression should I use ?

Any help would be most appreciated.