开发者

display data from more than one table

I am learning cakephp and doing an example.I have many tables in my database suc开发者_运维问答h as User,Post,Comment,Friend,Photo and each table has a foreign key user_id.Now I want to display user's photo,his/her friend's posts, comments on those posts,user's friends etc like any social networking site after successfull login.can any one please suggest me how to do that.

Thanks in advance.


You want to use the Containable Behavior to pull back a nested object graph that will have all of those fields.

http://book.cakephp.org/view/1323/Containable

You'll get back results like this (...pulled from the cakephp book)

[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
                    )
            )
    )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜