【发布时间】:2015-09-12 22:24:04
【问题描述】:
假设我有以下关联架构:
Person => [
hasMany => [
Courses => [Person.id = Courses.person_id]
],
Courses => [
belongTo => [
Schools => [School.id = Courses.school_id]
]
当我通过mydomain/person/view/1 查看一个人时,我需要一个表格来显示那个人的课程。在此表中,每门课程都需要显示学校的名称。
所以我在我的控制器上尝试了以下操作:
public function view($id = null)
{
$person = $this->Persons->get($id, [
'contain' => [
'Courses.Schools',
]
]);
$this->set('persons', $test);
$this->set('_serialize', ['person']);
}
我看到的是:
Person => [
firstname => test,
lastname => test,
courses => [
0 => [
id => 1,
shool_id => 1,
person_id => 1,
]
]
]
虽然我在包含选项中使用了它,但数组中没有学校。所以我不能显示学校的名字。我做错什么了吗?有什么指导方针如何在视图上显示这些字段。
【问题讨论】:
标签: php cakephp associations cakephp-3.0