displaying the field of other table in current gridview

I have two tables stud and employee want to display employee tables field in stud gridview

Make sure you have a reference from stud to emplyee in the Stud model (in function relations). Say the reference is named "employee", then you can reference employee in the CGrdView this way in the columns specification:




'columns'=>array(

  ...

  'employee.name' // works if you have a field named "name"

  ...

)



I have 2 tables group and member

group

id

name

member

id

group_id

firstname

lastname

it gives mi error-------Property "Group.group_id" is not defined.6180

Group.php

Where is in your table group field group_id?

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(


  'member' => array(self::HAS_MANY, 'Member', 'group_id'),


);

}

Member 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(


  'group' => array(self::BELONGS_TO, 'Group', 'group_id'),


);

}

you can access your relations as follow


// group gridview

member.firstname




// member gridview

group.name




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

                  'id'=>'member-grid',

                  'dataProvider'=>$member->search(),

                  'filter'=>$member,

                  'columns'=>array(

                    'group.name',

                    'firstname',

                    'lastname',

                    array(

                      'class'=>'CButtonColumn',

                    ),                    

                            ),

                 ));