ci+smarty结合配置方法

参考文档:http://hi.baidu.com/321v_cn/item/04a373737b044814d1dcb310

第一步(准备开源代码):
准备CodeIgniter 2.0.3版本(http://codeigniter.org.cn/downloads)
准备Smarty   3.1.3版本(http://www.smarty.net/download)

第二步(部署目录):
1:在htdocs建立一文件夹名为:demo_ci(名字可随意取)

2:解压ci包.将CI文件根目录(index.php同级目录)全有文件和文件夹拷至于demo_ci根目录.

3:解压smarty包,找到 libs文件夹,将libs拷贝至CI文件的application根目录下的libraries,将libs改名为smarty(名称可随意取,同下).在改名为smarty目录同级新建一个文件为:Ci_smarty.php

4:在demo_ci目录下新建tpl(模板文件夹),tpl_c(编辑的模板文件夹),cache(缓存文件夹),configs(配置文件夹)(不解四个文件夹作用,请百度)
第三步(让ci框架支持smarty模板):
1:找到demo_ci目录下的index.php文件,打开,在任意行添加二行代码(请记住ROOT定义的名称):
 if(!defined('ROOT'))
  define('ROOT',dirname(__FILE__));
 if (!defined('DS'))
     define('DS', DIRECTORY_SEPARATOR);//兼容linux,windows. 表示"/"

1:找到application/libraries目录下的Ci_smarty.php
打开Ci_smarty.php文件:添加代码如下:
<?php
require (ROOT.DS.APPPATH."libraries".DS."smarty".DS."Smarty.class.php");//APPPATH是ci系统预定义      // 的:application/ ,ROOT.DS是第三步的1定

义的.
class Ci_smarty extends Smarty{//继承smarty类,Ci_smarty注意如果文件名为大写,类名必须也大写
 function __construct(){
    parent::__construct();
    self::loadsmarty();
 }
 function loadsmarty(){  //配置smarty
   $this->template_dir=   ROOT  .DS .'tpl'.DS;
   $this->compile_dir  =   ROOT  .DS.'tpl_c'.DS;
   $this->config_dir    =   ROOT  . DS.'configs'.DS;
   $this->cache_dir     =   ROOT . DS.'cache'.DS;
   $this->left_delimiter = '<{';
   $this->right_delimiter = '}>';
 }
}
?>

第四步(测试ci+smarty...):
1:找到demo_ci/tpl
根目录下新建一模板文件test.html
 编写如下代码:
<html>
<head></head>
<body>
<{$test_content}>  //注意<{$name}>与smarty定义有关
</body>
</html>
1:找到application/controllers
根目录下新建一测试类 ci_smarty_test.php
 编写如下代码:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ci_smarty_test extends CI_Controller{ //控ci写法继承CI_Controller
 function __construct(){
  parent::__construct();
 }
 function index(){
    $this->load->library("ci_smarty");//ci_smarty首字母可小写.不解请百度
    $this->ci_smarty->assign("hello","<h1>this is hello page</h1>"); //smarty设置值
    $this->ci_smarty->display("test.html");
 }
}

?>

第五步:

打开浏览器输入:

http://127.0.0.1/demo_ci/index.php/ci_smarty_test

如果显示为:this is hello page


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值