1、准备
将smarty拷贝到application/libraries下,然后再根目录下下新建templates,templates_c,config,cache目录,结构如下:

2、修改入口文件
在入口文件index.php中新增:
define('ROOT', dirname(__FILE__));3、新建CI_Smarty.php
在libraries文件下新建CI_Smarty.php,写如下代码:
$value) {
$this->$key = $value;
}
} else {
//ROOT是Codeigniter在入口文件index.php定义的本web应用的根目录
$this->template_dir = $template_dir ? $template_dir : ROOT . '/templates';
$this->compile_dir = $compile_dir ? $compile_dir : ROOT . '/templates_c';
$this->config_dir = $config_dir ? $config_dir : ROOT . '/config';
$this->cache_dir = $cache_dir ? $cache_dir : ROOT . '/cache';
}
}
}4、在controller中使用
在控制器Welcome.php中写入使用方法,代码如下:
load->library('CI_Smarty');
}
/**
* smarty测试函数
*/
public function test()
{
$this->ci_smarty->assign('test', 'smarty');
$this->ci_smarty->display('test.tpl');
}
}5、创建模版试图
在templates文件夹下创建test.tpl文件,写入如下代码:
Codeigniter整合Smarty测试 这是 {$test} 测试
下一篇:PHP中微商城开源的示例分析