About the function code of using thinkphp framework to implement infinite reply comment

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.