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 に答える