CI 2.2 + smarty 3.1.18 完美整合配置成功
CI 2.2 + smarty 3.1.18 配置成功
一、准备文档下载 (CI 框架和smarty)
二、将Smarty-3.1.18 源码包里面的libs文件夹copy到ci的项目目录application下面的libraries文件夹下,并重命名为Smarty
三、application下面的libraries文件夹下,创建文件 Ci_smarty.php
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
require(APPPATH.'libraries/Smarty/Smarty.class.php');
class Ci_smarty extends Smarty
{
protected $ci; public function __construct()
{
parent::__construct(); $this->ci = & get_instance();
$this->ci->load->config('smarty');//加载smarty的配置文件
//获取相关的配置项
$this->cache_lifetime = $this->ci->config->item('cache_lifetime');
$this->caching = $this->ci->config->item('caching');
$this->template_dir = $this->ci->config->item('template_dir');
$this->compile_dir = $this->ci->config->item('compile_dir');
$this->cache_dir = $this->ci->config->item('cache_dir');
$this->use_sub_dirs = $this->ci->config->item('use_sub_dirs');
$this->left_delimiter = $this->ci->config->item('left_delimiter');
$this->right_delimiter = $this->ci->config->item('right_delimiter');
}
}
四、在config文件下创建smarty.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['cache_lifetime'] = 60; //更新周期
$config['caching'] = false; //是否使用缓存,项目在调试期间,不建议启用缓存
$config['template_dir'] = APPPATH.'views'; //设置模板目录
$config['compile_dir'] = APPPATH.'views/template_c'; //设置编译目录
$config['cache_dir'] = APPPATH.'views/cache'; //缓存文件夹
$config['use_sub_dirs'] = true; //子目录变量(是否在缓存文件夹中生成子目录)
$config['left_delimiter'] = '<{';
$config['right_delimiter'] = '}>';
顺便再CI项目目录下的 views 目录下创建目录:template_c,cache (创建的时候注意权限)
五、application->config找到autoload.php,修改如下
$autoload['libraries'] = array('Ci_smarty');
六、在application->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->ci_smarty->assign($key,$val);
}
public function display($html) {
$this->ci_smarty->display($html);
}
}
到此已经配置成功
下面进行测试
在application->controllers目录下新建welcome.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends MY_Controller
{
public function index()
{
$test='配置成功';
$this->assign('test',$test);
$this->display('index.html');
}
}
在application->views目录下新建index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>smarty配置测试</title>
</head>
<body>
<{$test}>
</body>
</html>
转自:http://codeigniter.org.cn/forums/forum.php?mod=viewthread&tid=18162
CI 2.2 + smarty 3.1.18 完美整合配置成功的更多相关文章
- ci框架与smarty的整合
ci框架与smarty的整合 来源:未知 时间:2014-10-20 11:38 阅读数:108 作者:xbdadmin [导读] Ci 和 smarty 的完美结合 Ci 结合 sma ...
- **【ci框架】PHP的CI框架集成Smarty的最佳方式
因为CI自带的模板功能不是很方便,所以大家普遍采用集成Smarty的方式来弥补CI这方面的不足. 本人在网上看了不少CI集成Smarty的教程,包括咱们CI论坛里面的一个精华帖子 http://cod ...
- Cacti+Nagios监控平台完美整合
Cacti+Nagios监控平台完美整合 本博文出自51CTO博客吴光科博主,有任何问题请进入博主页面互动讨论!博文地址:http://wgkgood.blog.51cto.com/1192594/1 ...
- java 一款可以与ssm框架完美整合的web报表控件
硕正套件运行于客户端(浏览器),与应用服务器(Application Server)技术无关,所以能完全用于J2EE. ASP.Net.php等技术开发的Web应用产品中. 硕正套件部署于服务器,支持 ...
- Ubuntu 18.04 下配置 HAXM 加速 Android模拟器
Ubuntu 18.04 下配置 HAXM 加速 Android模拟器 最近在vmware环境下搭建ubuntu18.04开发环境,开始发现总是运行android模拟器在console提示加载如下错误 ...
- [转] Cacti+Nagios监控平台完美整合
Cacti+Nagios监控平台完美整合 http://os.51cto.com/art/201411/458006.htm 整合nagios+cacti+微信.飞信实现网络监控报警 http://b ...
- Ubuntu 18.04LTS安装配置Java OpenJDK8
安装OpenJDK8 sudo apt-get install openjdk-8-jdk 配置Java环境变量 sudo vim /etc/profile 在profile末尾添加以下内容: exp ...
- Ubuntu 18.04安装配置Apache Ant
Ubuntu 18.04安装配置Apache Ant 文章目录 Ubuntu 18.04安装配置Apache Ant 下载 执行以下命令 `/etc/profile`中配置环境变量 载入配置 测试 执 ...
- Ubuntu 18.04 安装配置 go 语言
Ubuntu 18.04 安装配置 go 语言 1.下载 下载 jdk 到 Downloands 文件夹下 cd 进入 /usr/local, 创建 go 文件夹, 然后 cd 进这个文件夹 cd / ...
随机推荐
- VM CentOS7 网络配置问题汇总
0. 前言 在进行配置之前,我们首先需要明确几个概念: I. VM的网络连接方式 ①. 桥接模式(Bridge) 此模式下,VM centOS 在网络中作为一台独立主机存在,它可以访问网络中的任何 ...
- 哪个先执行:@PostConstruct和@Bean的initMethod?
结论: /** * step1:执行构造函数 * step2:执行使用@PostConstruct注解修饰的方法[如果有多个,则执行顺序不确定] * step3:执行@Bean注解中initMetho ...
- ASP.NET 之 MVC框架及搭建
一.MVC简介 MVC:Model-View-Controller(模型-视图-控制器),MVC是一种软件开发架构模式. 1.模型(Model) 模型对象是实现应用程序数据域逻辑的应用程序部件. 通常 ...
- python 3.x 爬虫基础---正则表达式
python 3.x 爬虫基础 python 3.x 爬虫基础---http headers详解 python 3.x 爬虫基础---Urllib详解 python 3.x 爬虫基础---Requer ...
- PHP中关于时间(戳)、时区、本地时间、UTC时间等的梳理
PHP中关于时间(戳).时区.本地时间.UTC时间等的梳理 在PHP开发中,我们经常会在时间问题上被搞糊涂,比如我们希望显示一个北京时间,但是当我们使用date函数进行输出时,却发现少了8个小时.几乎 ...
- mac系统终端sudo免输入密码技能get
1.需要在/etc/sudoers中配置. 这个文件的权限是r/r/n,配置之前需要加写权限. sudo chmod u-w /etc/sudoers 2.打开命令窗口sudo visudo 或者 s ...
- log4j2使用教程
Log4j2简介 log4j2是log4j 1.x 的升级版,2015年5月,Apache宣布log4j1.x 停止更新.最新版为1.2.17. log4j2参考了logback的一些优秀的设计, ...
- oracle数据库逐步学习总结【基础二】
原创作品,转载请在文字开头明显位置注明出处:https://www.cnblogs.com/sunshine5683/p/10067872.html 接着上一篇,继续总结! 五.oracle表管理 首 ...
- java工程师_基础_阶段一_HTML笔记篇
一.了解HTML语言 html:超文本标记语言. 二.HTML整体结构<html> <head> </head> <body> </body> ...
- UVAlive6807 Túnel de Rata (最小生成树)
题意 题目链接 Sol 神仙题Orz 我们考虑选的边的补集,可以很惊奇的发现,这个补集中的边恰好是原图中的一颗生成树: 并且答案就是所有边权的和减去这个边集中的边的权值: 于是我们只需要求最大生成树就 ...