You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.1 KiB

7 years ago
  1. <?php
  2. namespace app\fladmin\controller;
  3. class Search extends Base
  4. {
  5. public function _initialize()
  6. {
  7. parent::_initialize();
  8. }
  9. public function index()
  10. {
  11. $list = parent::pageList('search');
  12. $this->assign('page',$list->render());
  13. $this->assign('posts',$list);
  14. return $this->fetch();
  15. }
  16. public function doadd()
  17. {
  18. $_POST['pubdate'] = time();//更新时间
  19. $_POST['click'] = rand(200,500);//点击
  20. if(db('search')->insert($_POST))
  21. {
  22. $this->success('添加成功!', FLADMIN.'/Search' , 1);
  23. }
  24. else
  25. {
  26. $this->error('添加失败!请修改后重新添加', FLADMIN.'/Search/add' , 3);
  27. }
  28. }
  29. public function add()
  30. {
  31. return $this->fetch();
  32. }
  33. public function edit()
  34. {
  35. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  36. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  37. $this->assign('id',$id);
  38. $this->assign('row',db('search')->where("id=$id")->find());
  39. return $this->fetch();
  40. }
  41. public function doedit()
  42. {
  43. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else{$id="";exit;}
  44. if(!empty($_POST["keywords"])){$_POST['keywords']=str_replace("",",",$_POST["keywords"]);}else{$_POST['keywords']="";}//关键词
  45. $_POST['pubdate'] = time();//更新时间
  46. if(db('search')->where("id=$id")->update($_POST))
  47. {
  48. $this->success('修改成功!', FLADMIN.'/Search' , 1);
  49. }
  50. else
  51. {
  52. $this->error('修改失败!', FLADMIN.'/Search/edit?id='.$_POST["id"] , 3);
  53. }
  54. }
  55. public function del()
  56. {
  57. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$this->error('删除失败!请重新提交',FLADMIN.'/Search' , 3);} //if(preg_match('/[0-9]*/',$id)){}else{exit;}
  58. if(db("search")->where("id in ($id)")->delete())
  59. {
  60. $this->success('删除成功', FLADMIN.'/Search' , 1);
  61. }
  62. else
  63. {
  64. $this->error('删除失败!请重新提交', FLADMIN.'/Search', 3);
  65. }
  66. }
  67. }