Thinkphp带表情的评论回复实例
生活随笔
收集整理的這篇文章主要介紹了
Thinkphp带表情的评论回复实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Thinkphp帶表情的評論回復實例
基于Thinkphp開發的一個簡單的帶表情的評論回復實例,可以無限回復,適合新手學習或作為畢業設計作品等。
?
評論提交驗證
1 $(".submit-btn").click(function() { 2 var $this = $(this); 3 var name = $this.parent().siblings().children('.name1').val(); 4 var content = $this.parent().siblings().children('.comment').val(); 5 if (name == "" || content == "") { 6 alert("昵稱或者評論不能為空哦"); 7 return false; 8 } 9 });?
添加評論
1 $rules = array(//定義動態驗證規則 2 array('comment', 'require', '評論不能為空'), 3 array('username', 'require', '昵稱不能為空'), 4 // array('username', '3,15', '用戶名長度必須在3-15位之間!', 0, 'length', 3), 5 ); 6 $data = array( 7 'content' => I("post.comment"), 8 'ip' => get_client_ip(), 9 'add_time' => time(), 10 'pid' => I('post.pid'), 11 'author' => I('post.username'), 12 ); 13 14 $comment = M("comment"); // 實例化User對象 15 if (!$comment->validate($rules)->create()) {//驗證昵稱和評論 16 exit($comment->getError()); 17 } else { 18 $add = $comment->add($data); 19 if ($add) { 20 $this->success('評論成功'); 21 } else { 22 $this->error('評論失敗'); 23 } 24 }?
評論遞歸函數
1 function CommentList($pid = 0, &$commentList = array(), $spac = 0) { 2 static $i = 0; 3 $spac = $spac + 1; //初始為1級評論 4 $List = M('comment')-> 5 field('id,add_time,author,content,pid')-> 6 where(array('pid' => $pid))->order("id DESC")->select(); 7 foreach ($List as $k => $v) { 8 $commentList[$i]['level'] = $spac; //評論層級 9 $commentList[$i]['author'] = $v['author']; 10 $commentList[$i]['id'] = $v['id']; 11 $commentList[$i]['pid'] = $v['pid']; //此條評論的父id 12 $commentList[$i]['content'] = $v['content']; 13 $commentList[$i]['time'] = $v['add_time']; 14 // $commentList[$i]['pauthor']=$pautor; 15 $i++; 16 $this->CommentList($v['id'], $commentList, $spac); 17 } 18 return $commentList; 19 }本文轉自:https://www.sucaihuo.com/php/557.html 轉載請注明出處!
posted on 2019-09-08 11:32?mrlime 閱讀(...) 評論(...) 編輯 收藏轉載于:https://www.cnblogs.com/mrlime/p/11484878.html
總結
以上是生活随笔為你收集整理的Thinkphp带表情的评论回复实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: abaqus算出来的转角单位是什么_ab
- 下一篇: 仓库管理系统数据库设计