CI整合Smarty

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

1.到相应的站点下载smarty模板;

2.将源代码中的libs目录复制到项目的libraries目录下,改名为smarty3.0

3.在项目目录的libraries文件夹内新建文件ci_smarty.php,里面的内容如下:

<?php

defined('BASEPATH') OR exit('No direct scriptaccessallowed');

require_once(APPPATH . 'libraries/smarty3.0/Smarty.class.php');

class ci_smarty extends Smarty

{

PRotected $ci;

public function __construct(){

$this->ci = & get_instance();

$this->ci->load->config('smarty');//加载smarty的配置文件

//获取相关的配置项

$this->template_dir = $this->ci->config->item('template_dir');

$this->complie_dir = $this->ci->config->item('compile_dir');

$this->cache_dir = $this->ci->config->item('cache_dir');

$this->config_dir = $this->ci->config->item('config_dir');

$this->template_ext = $this->ci->config->item('template_ext');

$this->caching = $this->ci->config->item('caching');

$this->cache_lifetime = $this->ci->config->item('lefttime');

}

}

4.在项目目录的config文件夹内新建文件smarty.php文件,里面的内容如下:

5.在入口文件所在目录新建文件夹templates_c

6.在项目的配置文件夹下,autoload.php文件中加入

$autoload['libraries'] = array('ci_smarty');

7.在项目目录的core文件夹中新建文件MY_Controller.php 内容如下: // 扩展核心控制类

8.测试

控制器中

视图中

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航