CGridview Columns

My database has fields containing index numbers (eg 0=‘Yes’, 1=‘No’, 2=‘Maybe’ etc). I want to display the text meaning of these index numbers in a CGridView column.

The following code is what I’ve tried, but doesn’t work. The refTypeID column is blank. The filter is working correctly.

<?php $this->widget('zii.widgets.grid.CGridView', array(










)); ?>

refTypeID is the integer code, $ReferenceName is an array of text strings which are the values for each code (where key = refTypeID)

How can I display a human readable text value for an integer code ?

Of course, it’s easy when you know how …

The values to be displayed are already passed to the column in the ‘filter’ property.


Why not to make a property in the model?

Like that you will not be forced to write the array $referenceName each time you have to render, and if you change or add some code, you have only one place in wich to modify.

in the model:

public $referenceName= array(0='Yes', 1='No', 2='Maybe' );

public function getrefType()


   return $this->ReferenceName[$this->refTypeId];


In the view:


This kind of posprocess on database data lies better in the models.