This article mainly introduces the infinite reply comment function implemented by the thinkPHP framework, and briefly analyzes the related controller and view operation skills of thinkPHP to implement infinite reply in the form of examples. Friends in need can refer to this article
The example describes the infinite reply comment function implemented by the thinkPHP framework. Share it with everyone for your reference, the details are as follows:
If it is just a simple single reply comment, the operation is very simple. But the problem is how to achieve unlimited reply comments! So if there is only a single reply, many data tables need to be built, which is simply impossible to achieve. Then use the TP framework to achieve unlimited reply to comments, and pay attention to the use of the database.
control controller part:
function CommentList($pid = 0, &$commentList = array(), $spac = 0) { static $i = 0; $spac = $spac + 1; //初始为1级评论 $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; //评论层级 $commentList[$i]['author'] = $v['author']; $commentList[$i]['id'] = $v['id']; $commentList[$i]['pid'] = $v['pid']; //此条评论的父id $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 view part:
<volist name="commentList" id="vo"> <eq name="vo.pid" value="0"><hr class="solidline"/><else/><hr class="dottedline"/></eq> <p class="commentList " style="padding-left:{$vo['level']-1}cm"> <p><span class="user"> <if condition="($vo.pauthor eq NULL)">{$vo.author} <else /> {$vo.author}<span class="black" style="color: #000101">回复</span>{$vo.pauthor} </if> </span><a class="hf" id="{$vo.id}" style="float: right">回复</a><span class="hftime">{$vo.time|date="Y-m-d",###}</span></p> <p class="content">{$vo.content|reFace}</p> </p> </volist>
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Function codes for logging in, registering, and retrieving passwords under the thinkphp framework
About ThinkPhp framework Analysis of form validation and ajax validation issues
The above is the detailed content of About the functional code to implement unlimited reply to comments using thinkPHP framework. For more information, please follow other related articles on the PHP Chinese website!