Cgridview Show Name Instead Of Id

Hi guys, I have a “user” table in which a user has as another user as boss, so I’m having a relation with the same table


id_user = 1

name = Jhon Boss

boss = null

id_user = 2

name = Peter Smith

boss = 1 <- This is the id of Jhon Boss

So when I create a CGridView I need to display within the boss column the name of the boss instead of the id, if it isn’t null.




		'boss' // Here is where I need to display name instead of id

Thanks in advance!

Welcome to Yii forum!

Take a look at:

you could declare a association on User model boss like so

public function relations()


		return array(

			'myboss' => [self::BELONGS_TO, 'User', 'boss']



// then in your gridview you can access it like so