- 论坛徽章:
- 0
|
赚:高学平
codeigniter配置smarty模板
codeigniter是一个比较不错的轻量级的php开发web frame,我将ci结合smarty模板解释器使用,现在ci配置smarty的方法给出:
①下载smarty的源码包并且解压
②将smarty源码包中的libs核心类库重命名为Smarty并且经文件夹copy到ci的项目目录下的libraries下,同时在libraries文件夹下建立Cismarty.php文件。
③在Cismarty.php文件中写入如下的code- <?php<BR> if(!defined('BASEPATH'))exit('no dir');<BR> require_once (APPPATH.'libraries/Smarty/Smarty.class.php');<BR> class Cismarty extends Smarty<BR> {<BR> protected $ci;<BR> function __construct()<BR> {<BR> parent::__construct();<BR> $this->ci = &get_instance();<BR> $this->template_dir = $this->ci->config->item('template_dir');<BR> $this->compile_dir = $this->ci->config->item('compile_dir');<BR> $this->cache_dir = $this->ci->config->item('caching_dir');<BR> $this->config_dir = $this->ci->config->item('config_dir');<BR> $this->template_ext = $this->ci->config->item('template_ext');<BR> $this->caching = $this->ci->config->item('caching');<BR> $this->cache_lifetime = $this->ci->config->item('cache_lifetime');<BR> }<BR> }
复制代码 ④在项目目录下的cofig文件夹建立smarty.php文件,并且写入如下代码:- <?php<BR> if (! defined('BASEPATH')) exit('no direct base');<BR> $config['template_dir'] = APPPATH.'views';<BR> $config['compile_dir'] = FCPATH.'template_c';<BR> $config['caching_dir'] = FCPATH.'cache';<BR> $config['config_dir'] = FCPATH.'config';<BR> $config['caching'] = false;<BR> $config['cache_lifetime'] = '60';<BR> $config['template_ext'] = '.html';
复制代码 ⑤在项目目录下的config文件夹中的autoload.php文件中写入以下代码:- $autoload['config'] = array('smarty');
- $autoload['libraries'] = array('cismarty');
- 至此配置完毕,以下给出简单的测试程序
- view sourceprint? class Start extends CI_Controller
- {
- function __construct()
- {
- parent::__construct();
- $this->load->database();
- // $this->load->library('cismarty');
-
- }
-
- function smarty()
- {
- $title = 'title';
- $this->cismarty->assign('title',$title);
- $this->cismarty->display("test.html");
- }
- }
复制代码 现在自己在application下的views下建立一个test.html文件,传一个数据过去,如果配置正确那么可以看到测试页面和数据。 |
|