|
1, 把Smarty库放在ci库的libraries文件夹中,
2,在libraries里新建一个Smarty.php用来继承原生的Smarty类,代码如下:
PHP复制代码
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Smarty/Smarty.class.php");
/**
* DK_Smarty extends Smarty
* Author: Daker.W
* Create Time: 2010/08/11
**/
class DK_Smarty extends Smarty
{
var $cache = 0;
var $debug = false;
function DK_Smarty ($config = array())
{
$this->CI =& get_instance ();
if ( ! in_array('smarty_lang'.EXT , $this->CI->lang->is_loaded, TRUE))
{
$this->CI->lang->load('smarty');
}
$this->local_time = time();
$this->initialize($config);
log_message ('debug', "Smarty Class Initialized");
}
function initialize ($config = array(cache =>0, debug =>false))
{
foreach ($config as $key => $val)
{
if (isset($this->$key))
{
$this->$key = $val;
}
}
$this->left_delimiter = '<[url=mailto:!--{@]!--{@'[/url ];
$this->right_delimiter = [url =mailto :]'@}-->'[/url ];
define('TPL_PATH', APPPATH .'templates'.DIRECTORY_SEPARATOR);
$this->template_dir = TPL_PATH ;
$this->compile_dir = sprintf("%stemplates_c%s", APPPATH .DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
$this->config_dir = sprintf("%sconfig%s", APPPATH .DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
$this->cache_dir = sprintf("%scache%s", APPPATH .DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
if(!is_dir($this->compile_dir)){
mkdir($this->compile_dir, 0777);
}
if($this->caching && !is_dir($this->cache_dir)){
mkdir($this->cache_dir, 0777);
}
}
}//End Class
复制代码
最后目录结构如下
-------system
----------libraries
------------Smarty
------------Smarty.php
3,控制器中调用
PHP复制代码
class Testsmarty extends DK_Controller {
function DK_Testsmarty()
{
parent::DK_Controller();
}
function index()
{
$this->load->library('smarty');
$this->smarty->assign('test', 'wanggang');
$this->smarty->display('test/testsmarty.html');
}
}
复制代码 |
|