You should have added the code for the respective models or add the respective relations in both of the models but i will attempt to guide you so that you could follow up according to your code.
You can call the relation defined inside the Message
model to access the user and then display the username
.
About msg
table
i assume that the sender
and receiver
columns are holding the id
from the user
table, you should have the relations defined inside the Message
model or define one now and add the below inside your relations array (change your model names and field names if different).
As you have the sender
and receiver
2 columns both holding different user_id
so you need to define 2 relations.
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(
'_sender' => array(self::BELONGS_TO, 'User', 'sender'),
'_receiver' => array(self::BELONGS_TO, 'User', 'receiver'),
);
}
and then inside the GridView
change your column configurations to the following.
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
array(
'name'=>'sender',
'header'=>'Sender',
'htmlOptions'=>array('data-title'=>'Sender'),
'value'=>'$data->_sender->username'
),
array(
'name'=>'receiver',
'header'=>'Receiver',
'htmlOptions'=>array('data-title'=>'Receiver'),
'value'=>'$data->_receiver->username'
),
))
);
About sud_profile
table
You need to do the same for the sud_profile
table, define the relation and display it using the relation inside the gridview.
Your relation will look like below
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, 'User', 'user_id'),
);
}
And use the relation like below inside your gridview column configurations
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
array(
'name'=>'user_id',
'header'=>'Username',
'htmlOptions'=>array('data-title'=>'Sender'),
'value'=>'$data->_user->username'
),
))
);