BaseDiyView.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. private $relative_path;
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. $class = get_class($this);
  18. $routes = explode('\\', $class);
  19. if ($routes[ 0 ] == 'app') {
  20. //系统·组件:app/component/controller/Text
  21. $this->path = './' . $routes[ 0 ] . '/';
  22. $this->resource_path = __ROOT__ . '/' . $routes[ 0 ] . '/' . $routes[ 1 ] . '/view';
  23. $this->relative_path = $routes[ 0 ] . '/' . $routes[ 1 ] . '/view';
  24. } elseif ($routes[ 0 ] == 'addon') {
  25. //插件·组件:addon/seckill/component/controller/seckill
  26. $this->path = './' . $routes[ 0 ] . '/' . $routes[ 1 ] . '/';
  27. $this->resource_path = __ROOT__ . '/' . $routes[ 0 ] . '/' . $routes[ 1 ] . '/' . $routes[ 2 ] . '/view';
  28. $this->relative_path = $routes[ 0 ] . '/' . $routes[ 1 ] . '/' . $routes[ 2 ] . '/view';
  29. }
  30. }
  31. /**
  32. * 后台编辑界面
  33. */
  34. public function design()
  35. {
  36. }
  37. /**
  38. * 加载模板输出
  39. *
  40. * @access protected
  41. * @param string $template 模板文件名
  42. * @param array $vars 模板输出变量
  43. * @param array $replace 模板替换
  44. */
  45. protected function fetch($template = '', $vars = [], $replace = [])
  46. {
  47. $comp_folder_name = explode('/', $template)[ 0 ];// 获取组件文件夹名称
  48. $template = $this->path . 'component/view/' . $template;
  49. $this->resource_path .= '/' . $comp_folder_name; // 拼接组件文件夹名称
  50. $this->relative_path .= '/' . $comp_folder_name; // 拼接组件文件夹名称
  51. parent::assign('resource_path', $this->resource_path);
  52. parent::assign('relative_path', $this->relative_path);
  53. return parent::fetch($template, $vars, $replace);
  54. }
  55. }