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开发IO模型:阻塞&非阻塞&异步IO&多路复用&selectors
一 IO模型介绍 为了更好地了解IO模型,我们需要事先回顾下:同步.异步.阻塞.非阻塞 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非 ...
- MVC中Ajax post 和Ajax Get——提交对象Model
HTTP 请求:GET vs. POST两种在客户端和服务器端进行请求-响应的常用方法是:GET 和 POST.GET - 从指定的资源请求数据POST - 向指定的资源提交要处理的数据GET 基本上 ...
- Venom的简单使用
工具地址:https://github.com/r00t-3xp10it/venom 打开到venom目录,输入./venom.sh 打开程序 按回车键继续 这里有很多的模块,要用哪个模块就输入它的编 ...
- Wireshark捕获非加密的数据包
启动监听模式 root@sch01ar:~# airmon-ng start wlan0 启动Wireshark工具 root@sch01ar:~# wireshark 选择接口,这里选择wlan0m ...
- C#带百分比的进度条
功能需求: 如果程序中会执行一个耗时的计算过程,我想在用户点击按钮后,弹出一个进度条窗口,显示正在执行的进度(最好能带有百分比),执行完成后,进度条窗口关闭,回到主程序窗口. 在关闭子窗口之前父窗体不 ...
- 特别注意: range.Text.ToString(); 和 range.Value2.ToString(); 的区别
如果Excell的单元格里面是日期,前面显示2015年05月10日:后面的显示42134 也就是说:Text 和Value2的不同. using System; using System.Data; ...
- 监控和安全运维 1.7 nagios配置邮件告警
8. 配置邮件告警 服务端 vim /etc/nagios/objects/contacts.cfg 增加: define contact{ contact_name use generic-cont ...
- Python基础学习四 函数
1.内置函数 Python内置了很多有用的函数,是可以直接调用的. 参考链接:https://docs.python.org/3/library/functions.html 调用函数的时候,如果传入 ...
- pandas读写excel
import pandas as pd import numpy as np df = pd.read_csv("result.csv") # csv # df = pd.read ...
- Using Browser Link in Visual Studio 2013
题记:Browser Link是VS 2013开始引入的一个强大功能,让前端代码(比如AngularJS的代码)在VS中的修改更加轻而易举. 前 端代码是运行在浏览器中,而Visual Studio通 ...