12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- declare (strict_types = 1);
- namespace app;
- use think\App;
- use think\exception\ValidateException;
- use think\Validate;
- use think\View;
- /**
- * 控制器基础类
- */
- class BaseViewController extends BaseController
- {
- private $_view;
- public function __construct(App $app) {
- global $_A;
- $req = [
- '__IMAGES__' => config("app")['__IMAGES__'], // image变量
- '__JS__' => config("app")['__JS__'], // js变量
- '__CSS__' => config("app")['__CSS__'], // css变量
- '__ASSETS__' => config("app")['__ASSETS__'] //assets 变量
- ];
- //$this->_view = new View;
- $this->_view = \app('view');
- $this->_view->filter(function($content) use($req) {
- $content = strtr($content, $req);
- return $content;
- });
- parent::__construct($app);
- }
- /**
- * 模板参数
- * @param type $name 参数名称
- * @param type $value 输出模板
- */
- protected function assign($name, $value) {
- $this->_view->assign($name, $value);
- }
- /**
- * 输出模板
- * @global array $_A
- * @param array $template 模板名称
- * @return type
- */
- protected function display($template = '') {
- global $_A;
- $this->_view->assign("_A", $_A);
- return $this->_view->fetch($template);
- }
- }
|