<?php
namespace Libs\Vendor\Smarty;
/**
* Libs在APP_PATH目录下
* Class TplSmarty
* @package Libs\Vendor\Smarty
* 修改Think/ParseTemplateBehavior.class.php
* $engine = strtolower(C('TMPL_ENGINE_TYPE'));
* 修改为
* $engine = C('TMPL_ENGINE_TYPE'); // 使用上面的错误提示系统不支持
* 配置文件中添加Smarty的配置项
* // 模板配置
* 'TMPL_ENGINE_TYPE' => 'Libs\\Vendor\\Smarty\\TplSmarty', //Smarty模板引擎
*/
class TplSmarty{
private $smartyTpl = null;
public function __construct(){
vendor('Smarty.Smarty#class');
if(empty($this->smartyTpl) || !($this->smartyTpl instanceof TplSmarty) ){
$smarty = new \Smarty();
$smarty->caching = C('TMPL_CACHE_ON');
$smarty->template_dir = THEME_PATH;
$smarty->compile_dir = CACHE_PATH;
$smarty->cache_dir = TEMP_PATH;
if(C('TMPL_ENGINE_CONFIG')) {
$config = C('TMPL_ENGINE_CONFIG');
foreach ($config as $key=>$val){
$smarty->{$key} = $val;
}
}
$this->smartyTpl = $smarty;
}
}
/**
* 渲染模板输出
* @access public
* @param string $templateFile 模板文件名
* @param array $var 模板变量
* @return void
*/
public function fetch($templateFile,$var) {
$this->smartyTpl->assign($var);
$this->smartyTpl->display($templateFile);
}
}
Thinkphp Smarty 完美搭建WebApplication
最新推荐文章于 2018-10-04 22:10:05 发布