This article mainly introduced the thinkphp framework implementation of the infinite reply comment function, combined with the example form simple analysis of the thinkphp implementation of the infinite reply to the relevant controller, view operation skills, the need for friends can refer to the next
This article describes the thinkphp framework implementation of the infinite reply comment function. Share to everyone for your reference, as follows:
If it's just a simple single-reply comment, it's easy to do that. But the question is how to achieve unlimited responses to comments! So if it's just a single reply, it's impossible to build a lot of data sheets. Then use the TP framework to achieve unlimited replies to comments, attention to the use of the database.
Control Controller section:
function commentlist ($pid = 0, & $commentList = Array (), $spac = 0) { static $i = 0; $spac = $spac + 1; Initial Level 1 Comment $List = M (' comment '), field (' Id,add_time,author,content,pid '), where (Array (' pid ' = > $pid))->order ("id DESC")->select (); foreach ($List as $k = + $v) { $commentList [$i] [' level '] = $SPAC;//Comment Hierarchy $commentList [$i] [' author '] = $v [' Autho R ']; $commentList [$i] [' id '] = $v [' id ']; $commentList [$i] [' pid '] = $v [' pid ']; The parent ID of this comment $commentList [$i] [' content '] = $v [' content ']; $commentList [$i] [' time '] = $v [' Add_time ']; $commentList [$i] [' Pauthor ']= $pautor; $i + +; $this->commentlist ($v [' id '], $commentList, $SPAC); } return $commentList;}
View Views Section:
<volist name= "commentlist" id= "Vo" > <eq name= "vo.pid" value= "0" >
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!