CommentController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: Powerless < wzxaini9@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\user\controller;
  12. use app\user\model\CommentModel;
  13. use cmf\controller\UserBaseController;
  14. use app\user\model\UserModel;
  15. class CommentController extends UserBaseController
  16. {
  17. /**
  18. * 个人中心我的评论列表
  19. */
  20. public function index()
  21. {
  22. $user = cmf_get_current_user();
  23. $commentModel = new CommentModel();
  24. $comments = $commentModel->where(['user_id' => cmf_get_current_user_id(), 'delete_time' => 0])
  25. ->order('create_time DESC')->paginate();
  26. $this->assign($user);
  27. $this->assign("page", $comments->render());
  28. $this->assign("comments", $comments);
  29. return $this->fetch();
  30. }
  31. /**
  32. * 用户删除评论
  33. */
  34. public function delete()
  35. {
  36. if ($this->request->isPost()) {
  37. $id = $this->request->param("id", 0, "intval");
  38. $delete = new UserModel();
  39. $data = $delete->deleteComment($id);
  40. if ($data) {
  41. $this->success("删除成功!");
  42. } else {
  43. $this->error("删除失败!");
  44. }
  45. }
  46. }
  47. }