這篇文章主要介紹了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!