Yii Framework Forum: Reference Table Value Not Displayed In Yii Gridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Reference Table Value Not Displayed In Yii Gridview Rate Topic: -----

#1 User is offline   Rahil 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 10-June 14

Posted 10 June 2014 - 08:57 AM

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
0

#2 User is offline   nawin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 15-March 14
  • Location:இந்தியா, தமிழ்நாடு (India,TamilNadu)

Posted 10 June 2014 - 09:15 AM

View PostRahil, on 10 June 2014 - 08:57 AM, said:

Hi

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

That tells your models UserImages don't have any username attribute.
Check the Your UserImages models. If any upper case and lower case problem.
I think this is not username that is users.
0

#3 User is offline   Rahil 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 10-June 14

Posted 10 June 2014 - 09:22 AM

View Postnawin, on 10 June 2014 - 09:15 AM, said:

That tells your models UserImages don't have any username attribute.
Check the Your UserImages models. If any upper case and lower case problem.
I think this is not username that is users.


Yes UserImages has no "username" field, but i have setup relation with Users model which contains "username" field. and i want to display Users model username value based on matching user_id

    array('name'=>'username', 'value'=>'$data->user->username', 'header'=>'User Name'),

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users