Cgridview Call Model Function

You can add column display the data generated by object method,

for example a method of your model.

public static function getRoleName($userId)


	$sql 	  = "select role.RM_NAME from XXX role 

						where role.RM_ID=(select qqq from ZZZ where XXX=".$userId.")";

	$command  = Yii::app()->db->createCommand($sql)->queryAll();

	$roleName = $command[0]['RM_NAME'];

	return $roleName;   	 


In gridview

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







	'value' => function($data){

		     return User::getRoleName($data->UM_ID);



what is your question?

now onwards put this type of stuffs in Tips, Snippets and Tutorials Section yii forum. :)

Some admin please move it to right section

This is something irreverent thing you have posted here.i dont thing anything is useful in this post.It’s just like a self practice.Which is also in a wrong direction.

User::getRoleName($data->UM_ID); in place of this I want to Pass other model variable which are set above gridview

like User::getRoleName($model->client, $model->year, $data->id);

hows this possible ?? Please help

@RakhiKasat you can use php ‘use’ keyword passing variables to function.

check this Link