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.

84 lines
2.1 KiB

8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Admin\CommonController;
  4. use DB;
  5. class PageController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function index()
  12. {
  13. $data['posts'] = object_to_array(DB::table("page")->orderBy('id', 'desc')->get());
  14. return view('admin.page.index', $data);
  15. }
  16. public function doadd()
  17. {
  18. $_POST['pubdate'] = time();//更新时间
  19. $_POST['click'] = rand(200,500);//点击
  20. unset($_POST["_token"]);
  21. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  22. if(DB::table("page")->insert($_POST))
  23. {
  24. success_jump('添加成功!');
  25. }
  26. else
  27. {
  28. error_jump('添加失败!请修改后重新添加');
  29. }
  30. }
  31. public function add()
  32. {
  33. return view('admin.page.add');
  34. }
  35. public function edit()
  36. {
  37. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  38. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  39. $data['id'] = $id;
  40. $data['post'] = object_to_array(DB::table('page')->where('id', $id)->first(), 1);
  41. return view('admin.page.edit', $data);
  42. }
  43. public function doedit()
  44. {
  45. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  46. $_POST['pubdate'] = time();//更新时间
  47. unset($_POST["_token"]);
  48. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  49. if(DB::table('page')->where('id', $id)->update($_POST))
  50. {
  51. success_jump('修改成功!', route('admin_page'));
  52. }
  53. else
  54. {
  55. error_jump('修改失败!请修改后重新添加');
  56. }
  57. }
  58. public function del()
  59. {
  60. if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump("删除失败!请重新提交");} //if(preg_match('/[0-9]*/',$id)){}else{exit;}
  61. if(DB::table('page')->whereIn("id", explode(',', $id))->delete())
  62. {
  63. success_jump('删除成功');
  64. }
  65. else
  66. {
  67. error_jump("删除失败!请重新提交");
  68. }
  69. }
  70. }