create table zy_huifu ( code int auto_increment primary key, #回复代号 puser varchar(50), #回复人员 listcode int, #文章代号 time varchar(50), #回复时间 content text, #回复内容 pcode int, #父级代号 0文章 leval int, #级别 0顶级 1其它 isok int #已读未读0未读1已读 ); |
在控制器里面,我们需要去查询该文章下的所有评论及回复内容,并且注册到TP框架里面,这里调用了一个方法CommentList()来获取该文章下的评论回复:
//查询评论 $ahuifu = $this->CommentList($code,0); $this->assign("ahuifu",$ahuifu); |
//读取评论列表的递归,code为文章代号,pcode为父级代号 public function CommentList($code,$pcode){ $commentlist = array(); //存储评论数组 $list = Db::table("zy_huifu") ->alias('a') ->where("listcode",$code) ->where("pcode",$pcode) ->join("zy_user b","a.puser = b.uid") ->select(); foreach($list as $v){ $commentlist[] = $v; //查询子回复 $zi = $this->CommentList($code,$v["code"]); if(count($zi)){ foreach($zi as $v1){ $commentlist[] = $v1; } } } return $commentlist; } |
{volist name="ahuifu" id="vp"} {if condition="($vp.leval == 0)"} <div class="panel panel-default pl_list"> <div class="panel-body pl_list_nr"> <div class="show_nr_pl_tou"> <img src="{$vp.img}" width="30" height="30" /> <span>{$vp.name}</span> <span>{$vp.time|date="Y-m-d H:i:s",###}</span> <span><button class="btn btn-primary btn-xs show_huifu_btn" pcode="{$vp.code}">回复</button></span> </div> <div class="show_nr_pl_nr"> {$vp.content} </div> </div> </div> {else /} <div class="panel panel-default pl_list"> <div class="panel-body pl_list_nr" style="margin-left:50px"> <div class="show_nr_pl_tou"> <img src="{$vp.img}" width="30" height="30" /> <span>{$vp.name}</span> <span>{$vp.time|date="Y-m-d H:i:s",###}</span> <span><button class="btn btn-primary btn-xs show_huifu_btn" pcode="{$vp.code}">回复</button></span> </div> <div class="show_nr_pl_nr"> {$vp.content} </div> </div> </div> {/if} {/volist} |