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 视图 模板 ...
随机推荐
- python开发模块基础:序列化模块json,pickle,shelve
一,为什么要序列化 # 将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化'''比如,我们在python代码中计算的一个数据需要给另外一段程序使用,那我们怎么给?现在我们能想到的方法就是存在文 ...
- C#根据字体名通过注册表获取该字体文件路径(win10)两种方法推荐第二种
方法一: 直接先上源码: private System.Collections.Generic.SortedDictionary<string, string> ReadFontInfor ...
- Deep Learning 学习笔记(4):Logistic Regression 逻辑回归
逻辑回归主要用于解决分类问题,在现实中有更多的运用, 正常邮件or垃圾邮件 车or行人 涨价or不涨价 用我们EE的例子就是: 高电平or低电平 同时逻辑回归也是后面神经网络到深度学习的基础. (原来 ...
- 1.3Broker
Celery需要一种解决消息的发送和接受的方式,我们把这种用来存储消息的的中间装置叫做message broker, 也可叫做消息中间人. 作为中间人,我们有几种方案可选择: 1.RabbitMQ R ...
- leetcode452
public class Solution { public int FindMinArrowShots(int[,] points) { // multidimensional array cann ...
- Eclipse 代码风格配置
代码风格配置:
- RTMP_EnableWrite(rtmp)
发布流关键函数: RTMP_EnableWrite(rtmp); 将rtmp设置可写状态,会发出publish指令,否则是play指令:
- 继承ServletContextListener可以完成的事情
1.定时任务: 定时任务是从某个固定的时间开始执行特定的程序,继承这个方法,可以实现刚启动项目的时候执行某特定的程序,完成给客户部署的时即可以看到某个页面的效果. 2.初始化系统常量等: 这样来完成系 ...
- 算法技巧讲解》关于对于递推形DP的前缀和优化
这是在2016在长沙集训的第三天,一位学长讲解了“前缀和优化”这一技巧,并且他这一方法用的很6,个人觉得很有学习的必要. 这一技巧能使线性递推形DP的速度有着飞跃性的提升,从O(N2)优化到O(N)也 ...
- 【HDU3949】XOR
[题目大意] 给定一个数组,求这些数组通过异或能得到的数中的第k小是多少. 传送门:http://vjudge.net/problem/HDU-3949 [题解] 首先高斯消元求出线性基,然后将k按照 ...