Related Data Values In Cgridview

For some reason, I’m unable to access related data in CGridview using an expression. I’ve been able to use this with CDetailView with no problem, but when I try with CGridView, I get an error that “Property “CActiveDataProvider.territory0” is not defined.”

Area Model Relations:




public function relations()

	{

		return array(

			'territory0' => array(self::BELONGS_TO, 'Territories', 'territory'),

			'contacts' => array(self::HAS_MANY, 'Contacts', 'area'),

			'teams' => array(self::HAS_MANY, 'Teams', 'area'),

			'users' => array(self::HAS_MANY, 'Users', 'area'),

			'usersTmps' => array(self::HAS_MANY, 'UsersTmp', 'area'),

		);

	}



CGridView Code:




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

	'id'=>'goal-grid',

	'dataProvider'=>$dataProvider,

	'columns'=>array(

		'code',

		'name',

		'territory0.name',

		array(

			'value'=>$dataProvider->territory0->name

		)	

	),

	));



When I use territory0.name for a column value, it works, but the header just shows up as ‘name’ and I need it to show up as ‘Territory’. Any help would really be appreciated!

Hiya,

Add the key ‘header’ into the array




		array(

                        'header'=>'Territory',        // Add this!!!!

			'value'=>$dataProvider->territory0->name

		)