CI框架配置smarty

新建一个libraries 代码如下:

使用

$this->ci_smarty->set('pv',$pv);
$this->ci_smarty->set('pv_se',$pv_se);
$this->ci_smarty->build('home.html');

<?php
// load Smarty library
require_once(APPPATH.'libraries/smarty/Smarty.class.php');
 
class CI_smarty extends Smarty {
    private $viewData = array();
 
    function __construct() {
        parent :: __construct();
        $this -> template_dir = APPPATH . 'views/';
        $this -> compile_dir = APPPATH . 'cache/compile/';
        $this -> config_dir = APPPATH . 'config';
        $this -> cache_dir = APPPATH . 'cache/';
        $this -> left_delimiter = '<%';
        $this -> right_delimiter = '%>';
        $this->caching = true;
        //$this->testInstall();
        @$this -> clear_all_cache();
        //  $this->config_load('site.conf');
        parse_str($_SERVER['QUERY_STRING'],$_GET);
        $_GET = array_map('urldecode', $_GET);
        if (isset($_GET["_d"]) && $_GET["_d"] == 1) {
            $this -> debugging = true;
        }
    }
 
    function set($key, $val) {
        $arr = array();
        $arr[$key] = $val;
        if ($this->viewData) {
            $this->viewData = array_merge($this->viewData,$arr);
        } else {
            $this->viewData = $arr;
        }
        //$this->assign('v', $this->viewData);
    }
 
    function build($template)
    {
        $this->assign('v', $this->viewData);
        $this->display($template);
    }
}
?>

posted @   greengnn  阅读(2528)  评论(2编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示