1.下载smarty源码包,解压放置于项目目录 libriaries中

2.在libraries中建立Cismarty.php ,填写如下代码

<?php
if(!defined('BASEPATH')) EXIT('No direct script asscess allowed');
require_once( APPPATH . 'libraries/smarty-3.1.27/Smarty.class.php' ); class Cismarty extends Smarty {
protected $ci;
protected $template_ext;
protected $complie_dir;
public function __construct(){
parent::__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');
$this->left_delimiter = '<{';
$this->right_delimiter = '}>';
}
}

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

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['theme'] = 'default';
$config['template_dir'] = APPPATH . 'views';
$config['compile_dir'] = FCPATH . 'templates_c';
$config['cache_dir'] = FCPATH . 'cache';
$config['config_dir'] = FCPATH . 'configs';
$config['template_ext'] = '.html';
$config['caching'] = false;
$config['lefttime'] = 60;

4.在入口文件所在目录新建文件夹templates_c、cache、configs;

5.在项目目录下面的config目录中找到autoload.php文件

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

6.在项目目录的core文件夹中新建文件MY_Controller.php 内容如下:

<?php
if (!defined('BASEPATH')) exit('No direct access allowed'); class MY_Controller extends CI_Controller { public function __construct() { parent::__construct();
} public function assign($key,$val) { $this->cismarty->assign($key,$val);
} public function display($html) { $this->cismarty->display($html);
}
}

以上,配置完毕。

CI框架集成Smarty的更多相关文章

  1. **【ci框架】PHP的CI框架集成Smarty的最佳方式

    因为CI自带的模板功能不是很方便,所以大家普遍采用集成Smarty的方式来弥补CI这方面的不足. 本人在网上看了不少CI集成Smarty的教程,包括咱们CI论坛里面的一个精华帖子 http://cod ...

  2. Ci框架整合smarty模板引擎

    Ci框架整合smarty模板引擎 备注:下载smarty时,最好选择2.6版本,其他测试有坑,ci可以是2.2或其他 大体思路:将smarty封装成ci框架的一个类,然后重新配置一下smarty,这样 ...

  3. ci框架与smarty的整合

    ci框架与smarty的整合 来源:未知    时间:2014-10-20 11:38   阅读数:108   作者:xbdadmin [导读] Ci 和 smarty 的完美结合 Ci 结合 sma ...

  4. CI框架源码阅读笔记1 - 环境准备、基本术语和框架流程

    最开始使用CI框架的时候,就打算写一个CI源码阅读的笔记系列,可惜虎头蛇尾,一直没有行动.最近项目少,总算是有了一些时间去写一些东西.于是准备将之前的一些笔记和经验记录下来,一方面权作备忘,另一方面时 ...

  5. CI集成Smarty的实现方式

    给新伙伴的忠告:不要去想着有多复杂,看一遍绝对就会弄了! 这样集成的目的是什么? 因为我使用过CI和smarty,所以我就按自己的理解讲一下:CI框架在控制器.models方面做的很好,但在多变的视图 ...

  6. CI 2.2 + smarty 3.1.18 完美整合配置成功

    CI 2.2 + smarty 3.1.18 配置成功 一.准备文档下载  (CI 框架和smarty) 二.将Smarty-3.1.18 源码包里面的libs文件夹copy到ci的项目目录appli ...

  7. 【军哥谈CI框架】之CI中集成百度UEditor

    Hello,各位亲,新的一周来临啦,很高兴这么快又跟大家伙见面!话说上一回,军哥带大家用JQuery写了一个城市级联菜单的例子 ,不知道亲们学会了多少,是否自己可以独立写出来了呢. 军哥很是期待大家学 ...

  8. CI框架中集成CKEditor编辑器的教程

    CKEditor是在很多开发过程中都会用到的一个富文本编辑器,那么如何在CI框架中使用它呢?这里介绍了在CI下使用CKEditor的方法,版本比较低,是在CI 1.7.3下使用fckeditor 2. ...

  9. 第一天ci框架开发商城1

    ci框架开发商城1 1/28/2016 9:43:52 PM userguide删除 system application controllers 控制器 models 模型 views 视图 模板 ...

随机推荐

  1. 1073 Scientific Notation

    题意: 给出科学计数法的形式,转化成常规的表示,要求保留所有的有效位数 思路:纯粹的字符串处理问题,注意边界条件即可.如+1.23E+02这种,转化后是123,既不需要补0,也不需要添加小数点. 代码 ...

  2. angular 三大核心函数

    1.$watch  angular监听   由于angular一直在实时监听,所以比react和vue效率要低 $scope.$watch('aModel', function(newValue, o ...

  3. thinkphp使用自定义类方法

    1.通过Model调用 <?php /** * 积分模型 api接口 */ class ApiModel{ private $url = 'http://js.yunlutong.com/Cus ...

  4. 使用springboot写一个简单的测试用例

    使用springboot写一个简单的测试用例 目录结构 pom <?xml version="1.0" encoding="UTF-8"?> < ...

  5. oracle 函数中,一定要注意出现空记录和多条记录的处理方法

    今天折腾了3个小时,为一个以前不知道的oracle函数机制: 在sql查询中,如果一个查询未能获取记录,oracle不会报错 如select aa from bb where 1=2; 但在oracl ...

  6. keil:C语言里面调用汇编程序

    C语言直观,汇编效率高,C里面嵌入汇编是很好的选择. 路径大概如图: mian.c是我的C语言程序,Func.s是汇编程序. 主要是Init_1这个函数的实现在汇编文件里面,使用汇编实现的. 首先在C ...

  7. JQuery UI Datepicker中文显示的方法

    出自:http://www.aimks.com/method-to-display-the-jquery-ui-datepicker-chinese.html Query UI Datepicker这 ...

  8. MySQL备份还原之二使用mysqldump

    1 场景描述: create table gyj_t1(id int,name varchar(10)); insert into gyj_t1 values(1,'AAAAA'); commit; ...

  9. ASP.NET Core应用到Windows Service中

    托管到Windows Service中 众所周知,ASP.NET Core采用了和传统ASP.NET不同的托管和HTTP处理方式,即把服务器和托管环境完全解耦. ASP.NET Core内置了两个HT ...

  10. System.Security.Cryptography.CryptographicException: 出现了内部错误。

    引用:http://www.cnblogs.com/ithome8/p/5189926.html 我总结了一下出现证书无法加载的原因有以下三个 1.证书密码不正确,微信证书密码就是商户号 解决办法:请 ...