BaseDiyView.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\component\controller;
  3. use app\Controller;
  4. use liliuwei\think\Jump;
  5. class BaseDiyView extends Controller
  6. {
  7. use Jump;
  8. // 当前组件路径
  9. private $path;
  10. // 资源路径
  11. private $resource_path;
  12. /**
  13. * 后台编辑界面
  14. */
  15. public function design()
  16. {
  17. }
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. $class = get_class($this);
  22. $routes = explode('\\', $class);
  23. if ($routes[0] == 'app') {
  24. //系统·组件:app/component/controller/Text
  25. $this->path = './' . $routes[0] . '/';
  26. $this->resource_path = __ROOT__ . '/' . $routes[0] . '/' . $routes[1] . '/view';
  27. } elseif ($routes[0] == 'addon') {
  28. //插件·组件:addon/seckill/component/controller/seckill
  29. $this->path = './' . $routes[0] . '/' . $routes[1] . '/';
  30. $this->resource_path = __ROOT__ . '/' . $routes[0] . '/' . $routes[1] . '/' . $routes[2] . '/view';
  31. }
  32. }
  33. /**
  34. * 加载模板输出
  35. *
  36. * @access protected
  37. * @param string $template 模板文件名
  38. * @param array $vars 模板输出变量
  39. * @param array $replace 模板替换
  40. */
  41. protected function fetch($template = '', $vars = [], $replace = [])
  42. {
  43. $template = $this->path . 'component/view/' . $template;
  44. parent::assign("resource_path", $this->resource_path);
  45. return parent::fetch($template, $vars, $replace);
  46. }
  47. }