5.添加自己解析模板内容的类TemplateEy.class.php(这个放在thinkphp\Extend\Driver\Template目录下面)
只是将系统默认的ThinkTemplate.class.php类修改了fetch方法修改代码如下:
// 加载模板
public function fetch($templateFile,$templateContent,$templateVar) {
$this->tVar = $templateVar;
if($templateContent && !$templateFile) { //不缓存
if(C('LAYOUT_ON')) {
if(false !== strpos($templateContent,'{__NOLAYOUT__}')) { // 可以单独定义不使用布局
$templateContent = str_replace('{__NOLAYOUT__}','',$templateContent);
}else{ // 替换布局的主体内容
$layoutFile = THEME_PATH.C('LAYOUT_NAME').$this->config['template_suffix'];
$templateContent = str_replace($this->config['layout_item'],$templateContent,file_get_contents($layoutFile));
}
}
//编译模板内容
$templateContent = $this->compiler($templateContent);
extract($templateVar, EXTR_OVERWRITE);
echo $templateContent;
} else {
$templateCacheFile = $this->loadTemplate($templateFile,$templateContent);
// 模板阵列变量分解成为独立变量
extract($templateVar, EXTR_OVERWRITE);
//载入模版缓存文件
include $templateCacheFile;
}
}
6.调用如果数据库中模板的内容不存在那么我们还是去读数据库中的内容:
if( array_key_exists( $display_mode, $params['tpl'] ) && strlen($params['tpl'][$display_mode]) > 0 ){
return $this->fetch("Ext:New:Frontend:show",$params['tpl'][$display_mode]);
}else{
return $this->fetch("Ext:New:Frontend:show");
}
更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
pbootcms模板自动生成当前页面二维码二维码生成标签 {pboot:qrcode string=***} 使用说明: 用于生成对应文本的二维码图片,可用于产品列表页或详情页为每个
pbootcms模板中那些url怎么调用1、当前站点网址: {pboot:httpurl} 使用说明: 自适应获取当前访问网址,主要用于需要使用网站路径前缀的情况,如输
PbootCMS设置当前站点模板,模板子目录,黑白名单,敏感词过滤后台操作更换模板路径: 【基础内容】-【站点信息】-【站点模板】 配置后台模板子目录 【全局配置】-【配置参数
pbootcms公共标签调用1、模板文件嵌套引用 {include file=***.html} 使用说明: 文章来源:html5模板网 html5code.net 来源:html5模板网 html5code.net 可
PHP 使用二进制保存用户状态的实例下面小编就为大家分享一篇PHP 使用二进制保存用户状态的实例,具有很好的参考价值,希望对大家有所帮助。一起跟
Laravel框架之blade模板新手入门教程及小技巧Blade 是 laravel 提供的一个简单强大的模板引擎。下面这篇文章主要给大家介绍了关于Laravel框架之blade模板新手的入门