【发布时间】:2018-04-16 09:21:10
【问题描述】:
index.php
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
array(
'header' => 'User Name',
'value' => 'CHtml::encode($data->sud_profile->user_id)',//This will use the relationship and get all the details of the paticular user from users table
),
'subject',
'message',
我有两个表我想显示名称而不是 ID。
我的两张表是:
表 1
msg table
---------
id sender receiver subject message
------------------------------------
1 3 4 wish have a god
表 2
--------
sud_profile
-------------
id user_id firstname lastname
1 2 kumar rai
从这两个表中,我想根据 id 显示名称,例如 sender 和 user_id。
【问题讨论】:
-
添加您的两个模型或共享您在模型中声明的关系以及
msg表中的sender和receiver持有来自user表的ID?你想显示name吗?或username对于这些列,因为sud_profile表已经包含用户first和last名称? -
嘿,如果对您有帮助,请务必将答案标记为正确