Thinkphp带表情的评论回复实例

时间:2023-03-10 04:37:50
Thinkphp带表情的评论回复实例

基于Thinkphp开发的一个简单的带表情的评论回复实例,可以无限回复,适合新手学习或作为毕业设计作品等。

Thinkphp带表情的评论回复实例

评论提交验证

 $(".submit-btn").click(function() {
var $this = $(this);
var name = $this.parent().siblings().children('.name1').val();
var content = $this.parent().siblings().children('.comment').val();
if (name == "" || content == "") {
alert("昵称或者评论不能为空哦");
return false;
}
});

添加评论

 $rules = array(//定义动态验证规则
array('comment', 'require', '评论不能为空'),
array('username', 'require', '昵称不能为空'),
// array('username', '3,15', '用户名长度必须在3-15位之间!', 0, 'length', 3),
);
$data = array(
'content' => I("post.comment"),
'ip' => get_client_ip(),
'add_time' => time(),
'pid' => I('post.pid'),
'author' => I('post.username'),
); $comment = M("comment"); // 实例化User对象
if (!$comment->validate($rules)->create()) {//验证昵称和评论
exit($comment->getError());
} else {
$add = $comment->add($data);
if ($add) {
$this->success('评论成功');
} else {
$this->error('评论失败');
}
}

评论递归函数

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

本文转自:https://www.sucaihuo.com/php/557.html 转载请注明出处!