0
我正在学习cakephp并做一个例子。我在我的数据库中有很多表格,例如User,Post,Comment,Friend,Photo,每个表都有一个外键user_id.Now我想显示用户的照片,他/她的朋友的帖子,对这些帖子的评论,用户的朋友等喜欢任何社交网站成功login.can任何人后,请告诉我如何做到这一点。显示来自多个表的数据
在此先感谢。
我正在学习cakephp并做一个例子。我在我的数据库中有很多表格,例如User,Post,Comment,Friend,Photo,每个表都有一个外键user_id.Now我想显示用户的照片,他/她的朋友的帖子,对这些帖子的评论,用户的朋友等喜欢任何社交网站成功login.can任何人后,请告诉我如何做到这一点。显示来自多个表的数据
在此先感谢。
您想要使用可包含行为来拉回将包含所有这些字段的嵌套对象图。
http://book.cakephp.org/view/1323/Containable
你会得到这样的结果(...从CakePHP的书拉)
[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] => [email protected]
[website] => http://example.com
[comment] => First comment
[created] => 2008-05-18 00:00:00
)
[1] => Array
(
[id] => 2
[post_id] => 1
[author] => Sam
[email] => [email protected]
[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
)
)
)
没问题Vikram。如果您将其标记为接受的答案,我将不胜感激。 – 2011-05-17 12:35:01
嘿,有一个优秀的教程将教你如何做到这一切在CakePHP食谱中。看一看,试试吧! http://book.cakephp.org/view/1528/Blog – AlexBrand 2011-05-16 14:51:32
谢谢alex .... – vikram 2011-05-17 07:56:40