Yii:如何显示相关表的相关表中的字段? [英] Yii: how to show a field from a related table's related table?

查看:29
本文介绍了Yii:如何显示相关表的相关表中的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起......我的英语不好,所以我的问题可能完全不清楚.

Sorry ... my english is bad, so my question could be absolutely not clear.

我有这个表:团体用户报告

I have this tables: Groups Users Reports

关系:组 1 -> N 个用户 1 -> N 个报告

在报告的管理视图中,我使用的是 CGridView.

In the admin view of report I'm using a CGridView.

我实际上能够显示用户名....但是 show group.name 呢?

i'm actually able to show user name. ... but what about show group.name ?

如何建立关系?如何设置 CDbCriteria ?

How to setup relations ? How to setup CDbCriteria ?

我已经有了这个关系在报表模型中:

'user' => array(self::BELONGS_TO, 'Users', 'userId'),

这在用户模型中

'group' => array(self::BELONGS_TO, 'Gruppi', 'groupId'),

在报告模型中我有这个:

In Report Model I have this:

$criteria=new CDbCriteria;
$criteria->with = array ('user');

推荐答案

您应该能够像这样获得 group.name(从报告的管理视图中):

You should be able to get the group.name like this(from report's admin view):

user.group.name

你现在的关系就可以了,你也不需要使用任何标准.

And your current relations will do, also you do not have to use any criteria.

这篇关于Yii:如何显示相关表的相关表中的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆