Get the App
SLTechnology News&Howtos  ›  Development  › 

How is Thinkphp's emoji comment response developed?

Shulou Source: shulou.com Published: 2022-06-03 04:02:03 11月10日 Update

This article shows you how Thinkphp's emoticon comment responses are developed, the content is concise and easy to understand, and can definitely brighten your eyes. I hope you can get something through the details of this article.

Based on Thinkphp development of a simple emoticon comment reply example, can reply indefinitely, suitable for beginners to learn or as graduation design works.

Comment submission verification

(".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 ("nickname or comment cannot be empty"); return false })

Add comment

$rules = array (/ / define dynamic validation rules array ('comment',' require', 'comment cannot be empty'), array ('username',' require', 'nickname cannot be empty'), / / array ('username',' 315 characters, 'username length must be between 3-15 digits!' , 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") / / instantiate the User object if (! $comment- > validate ($rules)-> create ()) {/ / verify nicknames and comments exit ($comment- > getError ());} else {$add = $comment- > add ($data); if ($add) {$this- > success ('comment success');} else {$this- > error ('comment failed');}}

Comment recursive function

Function CommentList ($pid = 0, & $commentList = array (), $spac = 0) {static $I = 0; $spac = $spac + 1; / / initial level 1 comments $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; / / comment level $commentList [$I] [' author'] = $v ['author']; $commentList [$I] [' id'] = $v ['id']; $commentList [$I] [' pid'] = $v ['pid']; / / parent id of this comment $commentList [$I] [' content'] = $v ['content'] $commentList [$I] ['time'] = $v [' add_time']; / / $commentList [$I] ['pauthor'] = $pautor; $iTunes; $this- > CommentList ($v [' id'], $commentList, $spac);} return $commentList;} this is how Thinkphp's expressive comment responses are developed. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Comments emoticons development nicknames validation content examples skills knowledge concise successful concise between works functions dynamics objects that is hierarchies articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker Apple MySQL vpn