2011-08-17 76 views

回答

1

嗯,前几天我就这么做了,那是整合smarty系统的一步。

  1. 下载的Smarty从http://www.smarty.net/download
  2. 把里面的应用程序文件夹的Smarty/THIRD_PARTY
  3. 创建应用程序/库smarty.php文件并粘贴此

    require_once(APPPATH.'third_party/Smarty/libs/Smarty.class.php'); 
    
    class CI_Smarty extends Smarty { 
    
    protected $CI; 
    private $module; 
    
    public function __construct() 
    { 
        parent::__construct(); 
    
        // get CI istance 
        $this->CI =& get_instance(); 
        // fetch the calling module, need to check for views inside it 
        $this->module = $this->CI->router->fetch_module(); 
    
        // path 
        $this->setCompileDir(APPPATH . "cache/smarty/compiled"); 
        $this->setCacheDir(APPPATH . "cache/smarty/cached"); 
        $this->setTemplateDir(APPPATH . "views/templates"); 
    
        // to use $this inside our views/template 
        $this->assignByRef('this', $this->CI); 
    
        log_message('debug', "Smarty Class Initialized"); 
    } 
    
    public function display ($template, $cache_id = null, $compile_id = null, $parent = null) { 
        // automatically add .tpl extension if there is not in $template 
        if (strpos($template,'.') === FALSE) { 
         $template .= '.tpl'; 
        } 
        if (!empty($this->module)){ 
         $template = APPPATH . 'modules/' . $this->module . '/views/' . $template; 
        } 
        // call the original smarty function 
        parent::display($template, $cache_id, $compile_id, $parent); 
    } 
    } 
    
    /* End of file Smarty.php */ 
    /* Location: ./application/libraries/Smarty.php */ 
    

PS:抱歉,用于缩进

现在你可以在$ this-> load-> library('smarty')中使用smarty或者自动加载它,并在配置文件中添加smarty到$ autoload。

希望得到这个帮助! ^^