Hi
I am trying to display reference table value in CGridView but it doesn’t seems to be working. I have tried all possibility i found on internet.
Here is the relation. each user have multiple images and each image has single user.
UserImages.php model
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'user'=>array(self::BELONGS_TO,'Users','user_id')
);
}
Users.php Model
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'images'=>array(self::HAS_MANY,'UserImages','user_id')
);
}
User image grid view
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-images-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'image_id',
'user_id',
array('name'=>'username', 'value'=>'$data->user->username', 'header'=>'User Name'),
array('name'=>'filename','type'=>'raw','value'=>array($this,'gridThumb')),
'caption',
array(
'class'=>'CButtonColumn',
'template'=>'{update} | {delete}',
'updateButtonImageUrl'=>false,
'deleteButtonImageUrl'=>false,
),
),
));
But every time i got this error: Property "UserImages.username" is not defined.
Is there anything wrong i am doing ? please help.
Note : both table contains user_id column