当前位置:   article > 正文

fetch() php,fetch() · 常用的thinkPHP5内置函数和PHP7原生函数 · 看云

thinkphp fetch 界面函数

namespace think

class Template

fetch()

~~~

/**

* 渲染模板文件

* @access public

* @param string $template 模板文件

* @param array $vars 模板变量

* @param array $config 模板参数

* @return void

*/

public function fetch($template, $vars = [], $config = [])

{

if ($vars) {

$this->data = $vars;

}

if ($config) {

$this->config($config);

}

if (!empty($this->config['cache_id']) && $this->config['display_cache']) {

// 读取渲染缓存

$cacheContent = Cache::get($this->config['cache_id']);

if (false !== $cacheContent) {

echo $cacheContent;

return;

}

}

$template = $this->parseTemplateFile($template);

if ($template) {

$cacheFile = $this->config['cache_path'] . $this->config['cache_prefix'] . md5($template) . '.' . ltrim($this->config['cache_suffix'], '.');

if (!$this->checkCache($cacheFile)) {

// 缓存无效 重新模板编译

$content = file_get_contents($template);

$this->compiler($content, $cacheFile);

}

// 页面缓存

ob_start();

ob_implicit_flush(0);

// 读取编译存储

$this->storage->read($cacheFile, $this->data);

// 获取并清空缓存

$content = ob_get_clean();

if (!empty($this->config['cache_id']) && $this->config['display_cache']) {

// 缓存页面输出

Cache::set($this->config['cache_id'], $content, $this->config['cache_time']);

}

echo $content;

}

}

~~~

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/1002790
推荐阅读
相关标签
  

闽ICP备14008679号