基于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 转载请注明出处!

最新文章

  1. 意外关机引起 IntelliJ IDEA 报 org.jdom.input.JDOMParseException 异常的,解决办法
  2. Redis 对比 Memcached 并在 CentOS 下进行安装配置
  3. 【Android】友盟的自动更新组件
  4. python arguments *args and **args ** is for dictionaries, * is for lists or tuples.
  5. Ubuntu如何安装secureCRT
  6. uva 12096 The SetStack Computer
  7. ios 中的block应用
  8. <Win32_5>深入浅出Win32的计时器
  9. poj3429(有错)
  10. cef3和duilib简单仿有道词典学习
  11. VMware-vCenter-Server-Appliance VCSA升级步骤
  12. 尚硅谷springboot学习12-profile
  13. swift - UIWebView 和 WKWebView(iOS12 之后替换UIWebView)
  14. iOS webservice 接口使用方法
  15. POI的XWPFParagraph.getRuns分段问题 多余逗号
  16. Java Machine Learning Tools & Libraries--转载
  17. Winform、WPF、Silverlight、MFC区别与联系
  18. 每天一道算法题(12)——和为n的连续正数序列或者随机数
  19. 【python】-- web开发之HTML
  20. GitHub上易于高效开发的Android开源项目TOP20--适合新手

热门文章

  1. vmalloc/vfree问题思考记录
  2. 5面终于拿到了字节跳动offer! 鬼知道我经历了啥...
  3. 使用Redis实现延时任务(二)
  4. Docker容器日志路径
  5. stars-one的原创工具——APK签名验证破解工具
  6. 【HTML】---常用标签(1)
  7. Web前端基础(12):JavaScript(六)
  8. 神探Python程序员,带你千里捉小三!(附详情代码)
  9. MacOS~jenkins里解决docker执行权限问题
  10. 四步解决linux上sublime无法输入中文的问题