视图中的 CakePHP 3 显示来自 belongTo 关联模型的字段

CakePHP 3 on view show the field from a belongTo association model

假设我有以下关联模式:

Person => [
     hasMany => [
         Courses => [Person.id = Courses.person_id]
     ],
Courses => [
    belongTo => [
         Schools => [School.id = Courses.school_id]
    ]

当我通过 mydomain/person/view/1 查看一个人时,我需要一个 table 来显示那个人的课程。在此table中,每个课程都需要显示学校的名称。

所以我在控制器上尝试了以下操作:

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,
        ]
    ]
]

尽管我在包含选项中使用了它,但数组中没有学校。所以我不能显示学校的名称。我做错了什么吗?是否有任何指南如何在视图中显示这些字段。

基本上我为此感到抱歉。这是因为debugKit造成的。 debugkit 通过变量面板显示关联,直到我提到的级别,但我使用了 var_dump 并看到关联和相关字段是正确的 fetched/loaded。我信任 debugKit,我认为它们没有加载。