thinkphp5 $this->view->fech();解析

1.控制器直接调用$this->view->fetch();

2.调用~\thinkphp\library\think\View.php的fetch()方法;

$this->engine->$method($template, $vars, $config);

$this->engine 调用模板引擎

默认 ~\thinkphp\library\think\view\driver\Think.php

$this->engine-fetch($template, $vars, $config);//此时$template 为空

3.调用~\thinkphp\library\think\view\driver\Think.php的fetch()方法;

       if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
            // 获取模板文件名
            $template = $this->parseTemplate($template);//根据url获取文件名
        }

$this->template->fetch($template, $data, $config);

4.调用 ~\thinkphp\library\think\Template.php 的fetch()方法;

获取视图模板文件的内容并输出

5.~\thinkphp\library\think\View.php的fetch() 中获取并清空缓存

返回 视图文件内容

 // 获取并清空缓存
 $content = ob_get_clean();
 // 内容过滤标签
 Hook::listen('view_filter', $content);
 return $content;

猜你喜欢

转载自blog.csdn.net/weixin_39618204/article/details/81146895