ThinkPHP框架使用Smarty模板引擎

最近公司使用ThinkPHP框架,因此比较关注,想到以前公司使用的框架用的模板引擎是 Smarty,并且用的还挺顺手的。php

转到使用ThinkPHP自带的模板引擎还有点不习惯,因此在想换成Smarty模板引擎,网上看了一下,结果仍是比较简单。html

以此记录一下web

首先ThinkPHP框架里面要有Smarty扩展 位置在 ThinkPHP\Extend\Vendor\Smarty ,若是没有就去 Smarty官网下一个最新版吧,也推荐使用最新版的。通常完整版的ThinkPHP框架都含有 Smarty扩展的。 而后只需修改配置文件 Conf\config.php框架

<?phpreturn array(  //'配置项'=>'配置值'  'TMPL_ENGINE_TYPE'		=> 'Smarty',  'TMPL_ENGINE_CONFIG'	=> array(  'caching' => TRUE,  'template_dir' => TMPL_PATH,  'compile_dir' => TEMP_PATH,  'cache_dir' => CACHE_PATH,  'left_delimiter' => '{',  'right_delimiter' => '}',  ),
);?>

Action:this

<?phpclass IndexAction extends Action {  public function index(){    $data = array(      'asdf' => 1,'dfg' => 2,'asdfrg' => 3,'yhnfd' => 4,'bfws' => 1    );    $this->assign('test',$data);    $this->display();  }
}

html:code

{$smarty.now}
<br />
{foreach $test as $key=>$data}
{$key}:{$data}<br />
{/foreach}

最后输出:orm

1411459827htm

asdf:1模板引擎

dfg:2it

asdfrg:3

yhnfd:4

bfws:1

yes,这样就搞定了,使用Smarty模板就这么简单

相关文章
相关标签/搜索