CI框架集成Smarty
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的更多相关文章
- **【ci框架】PHP的CI框架集成Smarty的最佳方式
因为CI自带的模板功能不是很方便,所以大家普遍采用集成Smarty的方式来弥补CI这方面的不足. 本人在网上看了不少CI集成Smarty的教程,包括咱们CI论坛里面的一个精华帖子 http://cod ...
- Ci框架整合smarty模板引擎
Ci框架整合smarty模板引擎 备注:下载smarty时,最好选择2.6版本,其他测试有坑,ci可以是2.2或其他 大体思路:将smarty封装成ci框架的一个类,然后重新配置一下smarty,这样 ...
- ci框架与smarty的整合
ci框架与smarty的整合 来源:未知 时间:2014-10-20 11:38 阅读数:108 作者:xbdadmin [导读] Ci 和 smarty 的完美结合 Ci 结合 sma ...
- CI框架源码阅读笔记1 - 环境准备、基本术语和框架流程
最开始使用CI框架的时候,就打算写一个CI源码阅读的笔记系列,可惜虎头蛇尾,一直没有行动.最近项目少,总算是有了一些时间去写一些东西.于是准备将之前的一些笔记和经验记录下来,一方面权作备忘,另一方面时 ...
- CI集成Smarty的实现方式
给新伙伴的忠告:不要去想着有多复杂,看一遍绝对就会弄了! 这样集成的目的是什么? 因为我使用过CI和smarty,所以我就按自己的理解讲一下:CI框架在控制器.models方面做的很好,但在多变的视图 ...
- CI 2.2 + smarty 3.1.18 完美整合配置成功
CI 2.2 + smarty 3.1.18 配置成功 一.准备文档下载 (CI 框架和smarty) 二.将Smarty-3.1.18 源码包里面的libs文件夹copy到ci的项目目录appli ...
- 【军哥谈CI框架】之CI中集成百度UEditor
Hello,各位亲,新的一周来临啦,很高兴这么快又跟大家伙见面!话说上一回,军哥带大家用JQuery写了一个城市级联菜单的例子 ,不知道亲们学会了多少,是否自己可以独立写出来了呢. 军哥很是期待大家学 ...
- CI框架中集成CKEditor编辑器的教程
CKEditor是在很多开发过程中都会用到的一个富文本编辑器,那么如何在CI框架中使用它呢?这里介绍了在CI下使用CKEditor的方法,版本比较低,是在CI 1.7.3下使用fckeditor 2. ...
- 第一天ci框架开发商城1
ci框架开发商城1 1/28/2016 9:43:52 PM userguide删除 system application controllers 控制器 models 模型 views 视图 模板 ...
随机推荐
- spring-cloud配置eureka客户端
spring-cloud配置eureka客户端 eureka用来发现其他程序 需要提前配置eureka服务端,具体看 https://www.cnblogs.com/ye-hcj/p/10292944 ...
- 处理大数据对象clob数据和blob数据
直接上下代码: package com.learn.jdbc.chap06; import java.io.File; import java.io.FileInputStream; import j ...
- Libevent使用例子,从简单到复杂
转载请注明出处:http://blog.csdn.net/luotuo44/article/details/39670221 本文从简单到复杂,展示如何使用libevent.网上的许多例子都是只有服务 ...
- 0k6410定时器详细分析
看到一篇很好的博文,分析2410定时器中断的使用的,很详细,和大家分享一下 转载来源于http://www.cnblogs.com/Neddy/archive/2011/07/01/2095176.h ...
- 【原】Coursera—Andrew Ng机器学习—编程作业 Programming Exercise 3—多分类逻辑回归和神经网络
作业说明 Exercise 3,Week 4,使用Octave实现图片中手写数字 0-9 的识别,采用两种方式(1)多分类逻辑回归(2)多分类神经网络.对比结果. (1)多分类逻辑回归:实现 lrCo ...
- 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 5 Octave Tutorial—5.5 控制语句: for, while, if 语句
5.5 控制语句: for, while, if 语句 参考视频: 5 - 5 - Control Statements_ for, while, if statements (13 min).mkv ...
- 201671010140. 2016-2017-2 《Java程序设计》java学习第八周
第八周Java学习 本周,老师带领我们完善了一下继承,借口,拷贝,lambda表达式,内部类方面欠缺,不完善的地方,帮助我们查漏补缺. 以拷贝的学习为例,我本来对拷贝的理解非常浅 ...
- python小程序:备份文件
设计程序,有以下步骤: 需要备份的文件和目录由一个列表指定. 备份应该保存在主备份目录中. 文件备份成一个zip文件. zip存档的名称是当前的日期和时间. 解决方案: 版本一: #!/usr/bin ...
- codeforce453DIV2——D. GCD of Polynomials
题意 给出n(1–150). 输出两个多项式A,B从常数到最高次的系数,使得对两个多项式求gcd时,恰好经过n步得到结果. 多项式的gcd一步是指(A(x),B(x))变成(B,A mod B)的过程 ...
- DataTable 常用操作
//定义表结构 DataTable dt = new DataTable(); dt.Columns.Add("FactoryId"); 或dt.Columns.Add(new D ...