【发布时间】:2018-01-23 07:46:26
【问题描述】:
问题: 假设我有两张桌子,
Table1 Table2
-authorId -username
-moderatorId -id
目前我的看法是这样的,
[
'label' => 'Author',
'value' => function($something){
return $something->transaction->authorId ?? null;
},
'attribute' => 'author'
],
预期结果 我想在gridview中显示每个帖子的作者姓名, 我尝试使用 authorId 但它只显示作者的 id。 我应该如何使用“authorId”列映射到“username”列。
提前致谢,
【问题讨论】:
-
也许关系就是你要找的yiiframework.com/doc-2.0/…
-
如果您在上述表中的数据库中有外键,您可以通过 gii 在模型中轻松生成关系,然后在视图中简单地使用它们(参见上面的链接)。
标签: php gridview yii2 yii2-advanced-app yii2-basic-app