评论组件

显示评论组件:

  1. {:Comments("posts",$object_id)}
  2. <!-- 评论文章表里的某个id$object_id的文章-->

Comments方法说明:

参数1:评论内容所在的表,不带表前缀的表名称,如cmf_posts应该改为“posts”;

参数2:评论内容的id:

参数3:数组,目前支持tpl参数,如array(“tpl”=>”comment_custom”),这样设置就会加载模板目录Comment/coment_custom.html这个模板。

评论模板:
默认评论模板文件:Comment/comment.html

  1. <br>
  2. <h3>评论</h3>
  3. <div class="comment-area">
  4. <hr>
  5. <form class="form-horizontal comment-form" action="{:U('comment/comment/post')}" method="post">
  6. <div class="control-group">
  7. <div class="comment-postbox-wraper">
  8. <textarea class="form-control comment-postbox" placeholder="Write your comment here" style="min-height:90px;" name="content"></textarea>
  9. </div>
  10. </div>
  11. <div class="control-group">
  12. <button type="submit" class="btn pull-right btn-primary js-ajax-submit"><i class="fa fa-comment-o"></i> 发表评论</button>
  13. </div>
  14. <input type="hidden" name="post_table" value="{:sp_authencode('posts')}"/>
  15. <input type="hidden" name="post_id" value="{$post_id}"/>
  16. <input type="hidden" name="to_uid" value="0"/>
  17. <input type="hidden" name="parentid" value="0"/>
  18. </form>
  19. <script class="comment-tpl" type="text/html">
  20. <div class="comment" data-username="{$user.user_nicename}" data-uid="{$user.id}">
  21. <a class="pull-left" href="{:U('user/index/index',array('id'=>$user['id']))}">
  22. <img class="media-object avatar" src="{:U('user/public/avatar',array('id'=>$user['id']))}" class="headicon"/>
  23. </a>
  24. <div class="comment-body">
  25. <div class="comment-content"><a href="{:U('user/index/index',array('id'=>$user['id']))}">{$user.user_nicename}</a>:<span class="content"></span></div>
  26. <div><span class="time">刚刚</span> <a onclick="comment_reply(this);" href="javascript:;"><i class="fa fa-comment"></i></a></div>
  27. </div>
  28. <div class="clearfix"></div>
  29. </div>
  30. </script>
  31. <script class="comment-reply-box-tpl" type="text/html">
  32. <div class="comment-reply-submit">
  33. <div class="comment-reply-box">
  34. <input type="text" class="textbox" placeholder="回复">
  35. </div>
  36. <button class="btn pull-right" onclick="comment_submit(this);">回复</button>
  37. </div>
  38. </script>
  39. <hr>
  40. <div class="comments">
  41. <foreach name="comments" item="vo">
  42. <div class="comment" data-id="{$vo.id}" data-uid="{$vo.uid}" data-username="{$vo.full_name}" id="comment{$vo.id}">
  43. <a class="pull-left" href="{:U('user/index/index',array('id'=>$vo['uid']))}">
  44. <img class="media-object avatar" src="{:U('user/public/avatar',array('id'=>$vo['uid']))}" class="headicon"/>
  45. </a>
  46. <div class="comment-body">
  47. <div class="comment-content"><a href="{:U('user/index/index',array('id'=>$vo['uid']))}">{$vo.full_name}</a>:<span>{$vo.content}</span></div>
  48. <div><span class="time">{:date('m月d日 H:i',strtotime($vo['createtime']))}</span> <a onclick="comment_reply(this);" href="javascript:;"><i class="fa fa-comment"></i></a></div>
  49. <if condition="!empty($vo['children'])">
  50. <foreach name="vo.children" item="voo">
  51. <div class="comment" data-id="{$voo.id}" data-uid="{$voo.uid}" data-username="{$voo.full_name}" id="comment{$voo.id}">
  52. <a class="pull-left" href="{:U('user/index/index',array('id'=>$voo['uid']))}">
  53. <img class="media-object avatar" src="{:U('user/public/avatar',array('id'=>$voo['uid']))}" class="headicon"/>
  54. </a>
  55. <div class="comment-body">
  56. <div class="comment-content"><a href="{:U('user/index/index',array('id'=>$voo['uid']))}">{$voo.full_name}</a>:<span>回复 <a href="{:U('user/index/index',array('id'=>$voo['to_uid']))}">{$parent_comments[$voo['parentid']]['full_name']}</a> {$voo.content}</span></div>
  57. <div><span class="time">{:date('m月d日 H:i',strtotime($voo['createtime']))}</span> <a onclick="comment_reply(this);" href="javascript:;"><i class="fa fa-comment"></i></a></div>
  58. </div>
  59. <div class="clearfix"></div>
  60. </div>
  61. </foreach>
  62. </if>
  63. </div>
  64. <div class="clearfix"></div>
  65. </div>
  66. </foreach>
  67. </div>
  68. </div>