ThemeController.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * 样式管理
  5. * @author xusong
  6. * @version 0.0.1
  7. */
  8. class ThemeController extends CommonController {
  9. /**
  10. * [_initialize 前置操作-继承公共前置方法]
  11. */
  12. public function _initialize() {
  13. // 调用父类前置方法
  14. parent::_initialize();
  15. // 登录校验
  16. $this->Is_Login();
  17. // 权限校验
  18. $this->Is_Power();
  19. //要执行的表
  20. }
  21. /**
  22. * 主题列表
  23. * @author Devil
  24. */
  25. public function Index() {
  26. $List = M('theme')->order('id desc')->select();
  27. $this->assign('List', $List);
  28. $this->display('Index');
  29. }
  30. /**
  31. * [SaveInfo 文章添加/编辑页面]
  32. * @author Devil
  33. * @blog http://gong.gg/
  34. * @version 0.0.1
  35. * @datetime 2016-12-14T21:37:02+0800
  36. */
  37. public function SaveInfo() {
  38. $data = M('theme')->find(I('id'));
  39. $this->assign('data', $data);
  40. $this->display($data['view']);
  41. }
  42. /**
  43. * [Save 文章添加/编辑]
  44. * @author Devil
  45. * @blog http://gong.gg/
  46. * @version 0.0.1
  47. * @datetime 2016-12-14T21:37:02+0800
  48. */
  49. public function Save() {
  50. if (!IS_AjAX) {
  51. $this->error(L('common_unauthorized_access'));
  52. }
  53. $data['name'] = trim(I('name'));
  54. $data['type'] = trim(I('type'));
  55. // 添加
  56. if ($id = I('id')) {
  57. $data['id'] = $id;
  58. if (M('theme')->save($data)) {
  59. $this->ajaxReturn('更新成功');
  60. } else {
  61. $this->ajaxReturn('更新失败',400);
  62. }
  63. } else {
  64. $data['created_at'] = date('Y-m-d H:i:s');
  65. if ($bool=M('theme')->add($data)) {
  66. $this->ajaxReturn('新增成功');
  67. } else {
  68. echo M()->getLastSql();
  69. $this->ajaxReturn('新增失败',400);
  70. }
  71. }
  72. }
  73. /**
  74. * [Delete 删除]
  75. * @author Devil
  76. * @blog http://gong.gg/
  77. * @version 0.0.1
  78. * @datetime 2016-12-15T11:03:30+0800
  79. */
  80. public function Delete() {
  81. // 是否ajax请求
  82. if (!IS_AJAX) {
  83. $this->error(L('common_unauthorized_access'));
  84. }
  85. // 删除数据
  86. if (I('id')) {
  87. // 更新
  88. if (M('theme')->delete(I('id'))) {
  89. $this->ajaxReturn(L('common_operation_delete_success'));
  90. } else {
  91. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  92. }
  93. } else {
  94. $this->ajaxReturn(L('common_param_error'), -1);
  95. }
  96. }
  97. }