Reply to comment Thinkphp examples developed with a simple expression-based, unlimited return for novice learning or as a graduate design work and so on.
Comments submitted verification
. 1 $ ( "BTN-Submit.") The Click (. Function () { 2 var $ the this = $ ( the this ); . 3 var name = $ the this .. .Parent () SIBLINGS () Children ( 'NAME1.' ). Val (); . 4 var Content = $ the this .parent () SIBLINGS () Children ( 'Comment.'.. ) .val (); . 5 IF (name == "" || Content == "" ) { . 6 Alert ( "nickname or comment can not be empty oh" ); . 7 return to false ; . 8 } . 9 });
add comment
. 1 $ the rules = Array ( // define dynamic validation rule 2 Array ( 'Comment', 'the require', 'comments can not be empty'), . 3 Array ( 'username', 'the require', 'nickname can not be empty'), . 4 // Array ( 'username', '3,15', 'username must be between 3-15 bits!', 0, 'length',. 3), . 5 ); . 6 $ Data = Array ( . 7 ' Content '=> the I ( "post.comment"), . 8 ' IP '=> get_client_ip (), . 9 ' ADD_TIME '=> Time (), 10 ' PID '=> the I (' post.pid'), 11 'author' => I('post.username'), 12 is ); 13 is 14 $ Comment = M ( "Comment"); // instantiate a User object 15 IF ! ( $ Comment -> the validate ( $ the rules ) -> Create ()) { // verify the nickname and Reviews 16 Exit ( $ comment -> the getError ()); . 17 } the else { 18 is $ the Add = $ comment -> the Add ( $ Data ); . 19 IF ( $ the Add ) { 20 is $ the this -> success ( 'review success' ); 21 is } the else { 22 is $ the this -> error ( 'comments failed' ); 23 } 24 }
Comments recursive function
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 ; // Comments hierarchy . 9 $ commentList [ $ I ] [ 'author'] = $ V [ 'author' ]; 10 $ commentList [ $ I ] [ 'ID'] = $ V [ 'ID' ]; . 11 $ commentList [ $ I ] [ 'PID'] = $ V [ 'PID']; // this entry comments parent ID 12 is $ commentList [ $ I ] [ 'Content'] = $ V [ 'Content' ]; 13 is $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 }
This switched: https://www.sucaihuo.com/php/557.html please indicate the source!