Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 Yii 框架的新手。我的任务是列出两个表的组合数据,并在两个表之间匹配一个键。我有下表结构,
日志表 id,instance_id,user_id 实例表 id,instance_id,instance_name
日志表
id,instance_id,user_id
实例表
id,instance_id,instance_name
我必须在 CGridview 中显示“日志表”中的所有记录。我需要的是也在那个gridview中显示instance_name。
如何在这两个模型中设置关系以达到结果?
假设您有两个名为 Log 和 Instance 的模型:
在 Log.php 中添加方法:
公共函数关系(){返回数组('instance'=>数组(self :: BELONGS_TO,'Instance','instance_id'),);}
将 instance.instance_name 添加到您的 CGridView 小部件。
'columns'=>array( 'id', 'instance.instance_name', ...
...