2

我的模型中有可包含的行为我有一个这样的数组

  [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 的新手,我不知道该怎么做,在此先感谢。

4

1 回答 1

1

尝试这个

foreach($posts as $post){

 foreach($post['Comment'] as $comment){
   /*Display start here*/
     $post['Post']['title'];
     $comment['post_id'];
     $comment['author'];

 }

}

希望这有助于...

于 2013-03-11T08:23:20.407 回答