Models.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // |
  4. // +----------------------------------------------------------------------
  5. // |
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // |
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 模型管理
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller\cms;
  15. use app\admin\model\cms\Models as ModelsModel;
  16. use app\common\controller\Backend;
  17. class Models extends Backend
  18. {
  19. protected $modelClass = null;
  20. protected $modelValidate = true;
  21. protected $filepath = '';
  22. protected $noNeedRight = ['get_tpl_list'];
  23. protected function initialize()
  24. {
  25. parent::initialize();
  26. $this->modelClass = new ModelsModel;
  27. //取得当前内容模型模板存放目录
  28. $this->filepath = TEMPLATE_PATH . (empty(config('site.theme')) ? "default" : config('site.theme')) . DS . "cms" . DS;
  29. }
  30. //模型列表
  31. public function index()
  32. {
  33. if ($this->request->isAjax()) {
  34. $data = $this->modelClass->where('module', 'cms')->select();
  35. return json(["code" => 0, "data" => $data]);
  36. }
  37. return $this->fetch();
  38. }
  39. /**
  40. * 获取模板列表
  41. */
  42. public function get_tpl_list()
  43. {
  44. $type = $this->request->param('type', 'category');
  45. $keyValue = $this->request->param('keyValue');
  46. $path = $this->filepath . $type;
  47. $list = str_replace($this->filepath, '', glob($path . '*.html'));
  48. $arr = [];
  49. foreach ($list as $key => $value) {
  50. if (!empty($keyValue) && $value != $keyValue) {
  51. continue;
  52. }
  53. $arr[]['name'] = $value;
  54. }
  55. return json(['count' => count($arr), 'data' => $arr]);
  56. }
  57. }