Base.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace addons\cms\controller;
  3. use think\Request;
  4. /**
  5. * CMS控制器基类
  6. */
  7. class Base extends \think\addons\Controller
  8. {
  9. // 初始化
  10. public function __construct(Request $request = null)
  11. {
  12. parent::__construct($request);
  13. $config = get_addon_config('cms');
  14. // 设定主题模板目录
  15. $this->view->engine->config('view_path', $this->view->engine->config('view_path') . $config['theme'] . DS);
  16. // 加载自定义标签库
  17. //$this->view->engine->config('taglib_pre_load', 'addons\cms\taglib\Cms');
  18. // 默认渲染栏目为空
  19. $this->view->assign('__CHANNEL__', null);
  20. // 定义CMS首页的URL
  21. \think\Config::set('cms.indexurl', addon_url('cms/index/index', [], false));
  22. }
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. // 如果请求参数action的值为一个方法名,则直接调用
  27. $action = $this->request->post("action");
  28. if ($action && $this->request->isPost()) {
  29. return $this->$action();
  30. }
  31. }
  32. }