KnowController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\admin\controller;
  3. use cmf\controller\AdminBaseController;
  4. use think\Db;
  5. class KnowController extends AdminBaseController{
  6. public function index(){
  7. $lists = Db::name('know')->order('id desc')->paginate(20);
  8. $this->assign('lists',$lists);
  9. return $this->fetch();
  10. }
  11. public function add(){
  12. return $this->fetch();
  13. }
  14. public function addPost(){
  15. $param = $this->request->param();
  16. $param['create_time'] = time();
  17. if($param['author']!=''){
  18. $param['answer_time'] = time()+rand(3600*24,3600*100);
  19. }
  20. $res = Db::name('know')->insert($param);
  21. if($res){
  22. $this->success('添加成功');
  23. }else{
  24. $this->error('添加失败');
  25. }
  26. }
  27. public function edit(){
  28. $param = $this->request->param();
  29. isset($param['id']) or $this->error('需要id');
  30. $info = Db::name('know')->where('id',$param['id'])->find();
  31. $this->assign('info',$info);
  32. return $this->fetch();
  33. }
  34. public function editPost(){
  35. $param = $this->request->param();
  36. isset($param['id']) or $this->error('需要id');
  37. $res = Db::name('know')->update($param);
  38. if($res){
  39. $this->success('编辑成功');
  40. }else{
  41. $this->error('编辑失败');
  42. }
  43. }
  44. public function delete(){
  45. $param = $this->request->param();
  46. isset($param['id']) or $this->error('需要id');
  47. $res = Db::name('know')->where('id',$param['id'])->delete();
  48. if($res){
  49. $this->success('删除成功');
  50. }else{
  51. $this->error('删除失败');
  52. }
  53. }
  54. }
  55. ?>