我的模型中有可容纳的行为我有一个像这样的数组
[0] => Array
(
[Post] => Array
(
[id] => 1
[title] => First article
[content] => aaa
[created] => 2008-05-18 00:00:00
)
[Comment] => Array
(
[0] => Array
(
[id] => 1
[post_id] => 1
[author] => Daniel
[email] => dan@example.com
[website] => http://example.com
[comment] => First comment
[created] => 2008-05-18 00:00:00
)
[1] => Array
(
[id] => 2
[post_id] => 1
[author] => Sam
[email] => sam@example.net
[website] => http://example.net
[comment] => Second comment
[created] => 2008-05-18 00:00:00
)
)
[Tag] => Array
(
[0] => Array
(
[id] => 1
[name] => Awesome
)
[1] => Array
(
[id] => 2
[name] => Baking
)
)
)
如何在视图中显示字段的值?就像我想显示
的值 [Post][title]
[Comment][post_id]
[Comment][author]
我怎么能这样做,请帮我做那个我是cakephp的新手,我不知道怎么做,谢谢你。
答案 0 :(得分:1)
试试这个
foreach($posts as $post){
foreach($post['Comment'] as $comment){
/*Display start here*/
$post['Post']['title'];
$comment['post_id'];
$comment['author'];
}
}
希望这有帮助...