ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
[TOC] * * * * * ## 1 文件 >[info] 1 模板解析缓存 模板解析结果缓存机制目录think\template\driver\ 主要包括2种 * * * * * File.php 普通文件缓存机制 Sae.php Sae新浪云文件缓存机制 * * * * * >[info] 1 模板解析标签库 模板标签库入口文件 think\template\TagLib.php 模板标签库目录think\template\taglib\ Cx.php tp5内置标签库 ## 2 标签库设置 > 1 内置标签库 在[模板解析文件](http://www.kancloud.cn/zmwtp/tp5/120830)中定义的配置参数,设置了模板解析过程可以使用的标签库 ~~~ $config=[ 'taglib_build_in' => 'cx', 'taglib_pre_load' => '', ] ~~~ > 2 添加标签库 可以调用[Controller.php](http://www.kancloud.cn/zmwtp/tp5/119427)中的engine()方法, 在第二个参数$config中添加taglib_build_in,taglib_pre_load参数来添加标签库 ## 3 模板解析缓存 File.php文件 >[info] write()模板缓存保存 > read()模板缓存读取, > check()模板缓存检查 Sae.php文件 >[info] __construct() 构造函数 > write() 模板缓存保存 > read() 模板缓存读取 > check() 模板缓存检查 ## 4 总结 1 控制器Controller类中定义了View包含视图操作 `$this->view = \think\View::instance(Config::get());` 2 视图View类中定义了模板解析引擎think ~~~ protected $config = [ 'theme_on' => false, 'auto_detect_theme' => false, 'var_theme' => 't', 'default_theme' => 'default', 'view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS, 'view_layer' => VIEW_LAYER, 'parse_str' => [], 'engine_type' => 'think', 'namespace' => '\\think\\view\\driver\\', ]; ~~~ 3 系统默认模板解析驱动Think.php文件使用Template.php ` $this->template = new Template($config);` 4 系统模板解析文件Template.php中定义了标签库的使用 ~~~ $config=[ 'taglib_build_in' => 'cx', 'taglib_pre_load' => '', ] ~~~ 因此模板相关文件的层次如下 >[info] Controller.php ->View.php 视图操作 > View.php ->Think.php 模板引擎 > Think.php ->Template.php 系统模板解析 > Template.php ->Cx.php, 模板标签库