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(

	'id'=>'wallet1000-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

                array('name'=>'refTypeID','value'=>'$ReferenceName[$data->refTypeID]',

                      'filter'=>$ReferenceName),

		array('value'=>'number_format($data->amount,2)','name'=>'amount'),

		array('value'=>'number_format($data->balance,2)','name'=>'balance'),

	),

)); ?>



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.




        array('name'=>'refTypeID','value'=>'$this->filter[$data->refTypeID]','filter'=>$ReferenceName),



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:




array('name'=>'refTypeID','value'=>'$data->refType'),



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