CakePHP:如何查看外表中的详细信息?

时间:2015-01-03 16:25:02

标签: cakephp

我有两个型号:会员和职业。它们的结构是这样的:

MEMBER
member_id
last_name
first_name
vocation_id (foreign key)

VOCATION
vocation_id
description

在会员的视图页面中,我想显示姓氏,名字和职业描述。我似乎无法在文档中找到它。

我尝试了基本的CakePHP查看,但它只返回了职业的ID。我猜我需要在我的MembersController中创建一个新函数来查找他拥有的职业细节。我只需要关于如何做到这一点的标准。我将在文档中查看更多内容。也许我只是错过了那里的东西。如果我找到答案,我会更新这个问题。现在,这是我目前的代码:

<h1>#<?php echo h($member['Member']['member_id']); ?></h1>
<table>
    <tr>
        <td>Last Name</td>
        <td><?php echo $member['Member']['last_name']; ?></td>
    </tr>
    <tr>
        <td>First Name</td>
        <td><?php echo $member['Member']['first_name']; ?></td>
    </tr>
    <tr>
        <td>Vocation</td>
        <td><?php echo $member['Member']['vocation_id']; ?></td>
    </tr>
</table>

1 个答案:

答案 0 :(得分:2)

<tr>
    <td>Vocation</td>
    <td><?php echo $member['Vocation']['vocation_id']; ?></td>
</tr>
<tr>
    <td>Vocation description</td>
    <td><?php echo $member['Vocation']['description']; ?></td>
</tr>
相关问题