CodeIgniter(CI) 是一个小巧但功能强大的 PHP 框架,是一个简单而“优雅”的工具包,是进口的哦,但是他默认没有静态模板引擎,而smarty模板引擎是个非常优秀的模板引擎,拥有非常多的用户,许多开发者都熟悉他。这里就讲讲怎么在CI框架下添加smarty类,来使用smarty模板引擎。
1.下载smarty,官网:http://www.smarty.net/download.php 
把smarty的函数库(libs文件夹)解压放到ci框架下的application文件夹下的libraries里,/applicaton/libraries/smarty/
2.在根目录下的index.php里加入下面一句:

define(’APPNAME’, ‘application’);

3.在smarty文件夹里建cache、templates_c、configs文件夹(模板引擎的放缓存的文件夹,也可以放在其他地方,但要注意下一步SmartyExtended.php里做相应的修改)
4.在/application/libraries/下建smarty类文件SmartyExtended.php
SmartyExtended.php(代码)

<!–p
if (!defined(’BASEPATH’)) exit(’No direct script access allowed’);
 
define(’SMARTY_DIR’, BASEPATH . ‘../’ . APPNAME . ‘/libraries/smarty/’);
require(SMARTY_DIR . ‘Smarty.class.php’);
 
class SmartyExtended extends Smarty {
 
var $CI;
var $lang_code;
 
/**
* Constructor
*
* Loads the smarty class
*
* @access public
*/
function SmartyExtended() {
 
if (!file_exists(BASEPATH . ‘../’ . APPNAME . ‘/libraries/smarty/cache’))
{
mkdir(BASEPATH . ‘../’ . APPNAME . ‘/libraries/smarty/cache’, 0777);
}
 
$thi–>CI =&amp; get_instance();
$this-&gt;lang_code = [...]