2012-11-11 70 views
0

爲了實現此功能,我創建了一列replyTo,它與comment_id在同一個表中相關。原來的評論有這個0。我面臨的問題是什麼可能是展示他們的最佳方式。什麼是顯示嵌套評論的最佳方式?

在我的模型中,我創建了一個函數nested_comments()來獲取它們,並且在我看來我是這樣做的。

<? foreach($comments as $comment): ?> 
.... 
      <? foreach($comment->nested_comments() as $comm): ?> 

但是,如果我有一個嵌套評論級別,那就好了。其實,我希望有一種方法可以做到這一點。我不希望僅爲此目的創建另一個視圖文件和控制器。

回答

1

可以使用的功能,如下圖所示:

function getComments($comments){ 
     if(!is_array($comments)){ 
      return; 
     } 
    foreach($comments as $key => $value){ 
      // do what you want with comments 
      getComments($nestedComments); 
    } 
} 

仍無法使用的功能,但你可以以同樣的方式工作。

相關問題