ThinkPHP5中使用Smarty

1、用到的smarty類,我已經傳到CSDN了,點擊下載:http://download.csdn.net/download/leejianjun/10144076

2、將該類放到\thinkphp\library\think\view\driver文件夾下

3、\application\config.php中smarty部分這樣填寫

'template'               => [
        // 模板引擎類型 支持 php think 支持擴展
        //'type'         => 'Think',
        'type'         => 'Smarty',
        // 模板路徑
        'view_path'    => '',
        // 模板後綴
        'view_suffix'  => 'html',
        // 模板文件名分隔符
        'view_depr'    => DS,
        // 模板引擎普通標籤開始標記
        'tpl_begin'    => '<{',
        // 模板引擎普通標籤結束標記
        'tpl_end'      => '}>',
        // 標籤庫標籤開始標記
        'taglib_begin' => '{',
        // 標籤庫標籤結束標記
        'taglib_end'   => '}',
    ],

4、\application\index\controller\Index.php控制器中這樣寫

namespace app\index\controller;
//需要繼承
class Index extends \think\Controller{
    public function index(){
        // 模板變量賦值
        //$this->assign('name','ThinkPHP');
        // 或者批量賦值
        $this->assign([
            'name'  => 'ThinkPHP',
            'email' => '[email protected]'
        ]);
        // 模板輸出
        return $this->fetch('index');
    }
}
5、\application\index\view\Index\index.html模板中這樣寫:

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>test</title>
</head>
<body>
<{$name}><br/>
<{$email}>
</body>
</html>

大笑運行結果:




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章