Config.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use app\admin\model\Admin;
  4. use app\admin\model\AuthGroupAccess;
  5. use app\admin\model\cms\ChannelAdmin;
  6. use app\common\controller\Backend;
  7. use app\admin\model\cms\Channel as ChannelModel;
  8. use fast\Tree;
  9. use think\addons\Service;
  10. use think\Exception;
  11. /**
  12. * 系统配置
  13. *
  14. * @icon fa fa-gears
  15. */
  16. class Config extends Backend
  17. {
  18. /**
  19. * 查看
  20. */
  21. public function index()
  22. {
  23. $name = 'cms';
  24. $info = get_addon_info($name);
  25. $config = get_addon_fullconfig($name);
  26. if (!$info) {
  27. $this->error(__('No Results were found'));
  28. }
  29. if ($this->request->isPost()) {
  30. $params = $this->request->post("row/a", [], 'trim');
  31. if ($params) {
  32. foreach ($config as $k => &$v) {
  33. if (isset($params[$v['name']])) {
  34. if ($v['type'] == 'array') {
  35. $params[$v['name']] = is_array($params[$v['name']]) ? $params[$v['name']] : (array)json_decode($params[$v['name']], true);
  36. $value = $params[$v['name']];
  37. } else {
  38. $value = is_array($params[$v['name']]) ? implode(',', $params[$v['name']]) : $params[$v['name']];
  39. }
  40. $v['value'] = $value;
  41. }
  42. }
  43. try {
  44. //更新配置文件
  45. set_addon_fullconfig($name, $config);
  46. Service::refresh();
  47. $this->success();
  48. } catch (Exception $e) {
  49. $this->error(__($e->getMessage()));
  50. }
  51. }
  52. $this->error(__('Parameter %s can not be empty', ''));
  53. }
  54. $tips = [];
  55. foreach ($config as $index => &$item) {
  56. if ($item['name'] == '__tips__') {
  57. $tips = $item;
  58. unset($config[$index]);
  59. }
  60. }
  61. $this->view->assign("addon", ['info' => $info, 'config' => $config, 'tips' => $tips]);
  62. $configFile = ADDON_PATH . $name . DS . 'config.html';
  63. $viewFile = is_file($configFile) ? $configFile : '';
  64. return $this->view->fetch($viewFile);
  65. }
  66. }