Do i config CDataColumn in CGridView wrong?

Hi all,

I try to convert int data to string in CGridView and this is my codes.




// view

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

	'id'=>'administrator-grid',

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

	'filter'=>$model,

	'columns'=>array(

		'username',

		array(

			'name'=>'status',

			'type'=>'html',

			'value'=> ($model->getStatus($data->status))

		),

		'email'

	),

)); 




// model

class Administrator extends CActiveRecord

{

       ............

	public function getAllStatus()

	{

		return array(

			0=>"Disabled",

			1=>"Member" ,

			2=>"Administrator"

		);

	}

	

	public function getStatus($status)

	{

		$array  = self::getAllStatus();

		return $array[$status];

	}

}



in Status column, it shows nothing. what i do wrong?

someone help, thanks.

The value of the value property should be enclosed in quotes, check the docs - http://www.yiiframework.com/doc/api/1.1/CDataColumn#value-detail

btw, when you post code… please use the code button (<> on the editor toolbar) so that the code is more readable

And welcome to the yii forum

Sorry for code format.

Now i found a solution. just inherit __get function

but i think it not good way.

I don’t understand what you mean with inherit __get…

you just need to put the expression in a string… like:


'value'=>'$model->getStatus($data->status)',

Got it.

Thanks a lot. :lol: