關於用thinkPHP架構實現無限回複評論的功能代碼

來源:互聯網
上載者:User
這篇文章主要介紹了thinkPHP架構實現的無限回複評論功能,結合執行個體形式簡單分析了thinkPHP實現無限回複的相關控制器、視圖操作技巧,需要的朋友可以參考下

本文執行個體講述了thinkPHP架構實現的無限回複評論功能。分享給大家供大家參考,具體如下:

如果只是簡單的單回複的評論的話,那樣操作是很簡單的。但問題就是如何?無限的回複評論呢!那麼如果只是單回複的話,需要建好多的資料表,是根本不可能實現的。那麼用TP架構實現無限回複評論,注意資料庫的使用。

control控制器部分:

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視圖部分:

<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>

以上就是本文的全部內容,希望對大家的學習有所協助,更多相關內容請關注topic.alibabacloud.com!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.