Home > Backend Development > PHP Tutorial > About the functional code to implement unlimited reply to comments using thinkPHP framework

About the functional code to implement unlimited reply to comments using thinkPHP framework

不言
Release: 2023-03-31 06:34:01
Original
2575 people have browsed it

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;
}
Copy after login

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[&#39;level&#39;]-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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template