php smarty restful,CodeIgniter2.1.3整合smarty3.1.12

一、程序下载

下载CodeIgniter2.1.3(以下简称CI)与smarty3.1.12

二、安装CI

解压CI至网站(本次网站测试地址为http://local.ci.com)根目录下面,安装成功后会出现以下内容

三、整合CI与smarty

1、解压smarty压缩包,拷贝libs至libraries目录下并改名为smarty

2、在libraries目录下新建smarty.php,添加以下内容

if(!defined('BASEPATH')) exit('No direct script access allowed');

require(APPPATH.'libraries/smarty/Smarty.class.php');

class CI_Smarty extends Smarty{

public function __construct(){

parent::__construct();

$this->cache_lifetime = 30*24*3600; //更新周期

$this->caching=false; //是否使用缓存,项目在调试期间,不建议启用缓存

$this->template_dir = APPPATH.'views'; //设置模板目录

$this->compile_dir = APPPATH.'tpl_c'; //设置编译目录

$this->cache_dir = APPPATH.'cache'; //缓存文件夹

$this->use_sub_dirs = false; //子目录变量(是否在缓存文件夹中生成子目录)

$this->left_delimiter = '

$this->right_delimiter = '}>';

}

}

注意:__construct()函数里的parent::__construct();一定要加上,不然会出现错误

3、在项目目录下的config文件夹中的autoload.php文件中找到以下代码:

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

// 改为

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

截止到现在,CI与smarty整合已经完成,接下来我们来进行测试验证配置是否正确

打开application\controllers目录下的welcome.php将所有代码改为

class Welcome extends CI_Controller {

public function index(){

$title='smarty配置成功啦!!!';

$this->smarty->assign('title',$title);

$this->smarty->display('index.html');

}

}

在view目录下新建index.html文件,写入

smarty配置测试

在浏览器地址栏里输入http://local.ci.com,即可看到smarty配置成功啦!!!这条信息

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值