2011-05-16 92 views
0

我正在學習cakephp並做一個例子。我在我的數據庫中有很多表格,例如User,Post,Comment,Friend,Photo,每個表都有一個外鍵user_id.Now我想顯示用戶的照片,他/她的朋友的帖子,對這些帖子的評論,用戶的朋友等喜歡任何社交網站成功login.can任何人後,請告訴我如何做到這一點。顯示來自多個表的數據

在此先感謝。

+1

嘿,有一個優秀的教程將教你如何做到這一切在CakePHP食譜中。看一看,試試吧! http://book.cakephp.org/view/1528/Blog – AlexBrand 2011-05-16 14:51:32

+0

謝謝alex .... – vikram 2011-05-17 07:56:40

回答

0

您想要使用可包含行爲來拉回將包含所有這些字段的嵌套對象圖。

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

沒問題Vikram。如果您將其標記爲接受的答案,我將不勝感激。 – 2011-05-17 12:35:01

相關問題