BaseViewController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app;
  4. use think\App;
  5. use think\exception\ValidateException;
  6. use think\Validate;
  7. use think\View;
  8. /**
  9. * 控制器基础类
  10. */
  11. class BaseViewController extends BaseController
  12. {
  13. private $_view;
  14. public function __construct(App $app) {
  15. global $_A;
  16. $req = [
  17. '__IMAGES__' => config("app")['__IMAGES__'], // image变量
  18. '__JS__' => config("app")['__JS__'], // js变量
  19. '__CSS__' => config("app")['__CSS__'], // css变量
  20. '__ASSETS__' => config("app")['__ASSETS__'] //assets 变量
  21. ];
  22. //$this->_view = new View;
  23. $this->_view = \app('view');
  24. $this->_view->filter(function($content) use($req) {
  25. $content = strtr($content, $req);
  26. return $content;
  27. });
  28. parent::__construct($app);
  29. }
  30. /**
  31. * 模板参数
  32. * @param type $name 参数名称
  33. * @param type $value 输出模板
  34. */
  35. protected function assign($name, $value) {
  36. $this->_view->assign($name, $value);
  37. }
  38. /**
  39. * 输出模板
  40. * @global array $_A
  41. * @param array $template 模板名称
  42. * @return type
  43. */
  44. protected function display($template = '') {
  45. global $_A;
  46. $this->_view->assign("_A", $_A);
  47. return $this->_view->fetch($template);
  48. }
  49. }