【发布时间】:2012-02-06 03:37:15
【问题描述】:
我是 cakephp 的新手 .. 抱歉,如果我的问题看起来很基本 .. 我有模型:用户、帖子、评论,所有相关且需要展示 帖子视图上的 cmets .... 但也想显示用户名,我无法访问用户模型的这个字段。 我在comment.php 模型中有user_id 和post_id,在post.php 模型中有user_id,但是在循环内部如何访问用户模型的用户名字段??
我在...帖子/view.ctp上有这个
<?php foreach ($post['Comment'] as $comment): ?>
<tr<?php echo $class;?>>
// this does not work
// echo $comment['user_id']['username'];
<td><?php echo $comment['user_id']; ?>
</td>
</tr>
<tr>
<td><?php echo $comment['created'];?></td>
<td></td>
</tr>
<tr>
<td><?php echo $comment['content'];?></td>
</tr>
<?php endforeach; ?>
</table>
那我该如何解决呢?谢谢...
【问题讨论】: