php ci2.2与smarty3.1.20整合
1.下载ci框架与smarty,在此不再赘述
2.将CodeIgniter-2.2-stable.zip解压放到php根目录下
3.解压Smarty-3.1.20.zip,将lib文件夹copy到ci的application\libraries目录下
并新建Ci_smarty.php文件
<?php /** * smarty文件加载类 * */ if(!defined('BASEPATH')) exit('No direct script access allowed'); require(APPPATH.'libraries/libs/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'); } } ?>
4.在ci的application\config目录下
新建smarty.php文件
<?php if(!defined('BASEPATH')) exit('No direct script access allowed'); $config['cache_lifetime'] = 30*24*3600; $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'] = false; //子目录变量(是否在缓存文件夹中生成子目录) $config['left_delimiter'] = '<{'; $config['right_delimiter'] = '}>'; ?>
5.在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); } } ?>
6.在application/config/autoload.php文 件添加找到$autoload['libraries']array();添加Ci_smarty如下:
$autoload['libraries'] = array('Ci_smarty');
至此配置完毕,实现了,ci与smarty的无缝整合
7.测试
修改application/controllers/welcome.php如下:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends MY_Controller { public function index() { $test='ci 2.2 + smarty 3.1.20 配置成功'; $this->assign('test',$test); $this->display('test.html'); } } ?>在applicaction/views下新建test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>smarty配置测试</title> </head> <body> <{$test}> </body> </html>
相关推荐
2015年12月24日最新版:smarty-3.1.29
smarty 3.1.27 2015年8月最新版本的,如果官网下载不了就用这个吧。哈哈
smarty-3.1.24.zip
Smarty-3.1.21 最新发布版本
Smarty是一个使用PHP写出来的模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离。
collection php source code.
Smarty v3.1.48.zip
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
Smarty-3.1.21官方版本,多个途径给予下载
Smarty PHP模板引擎是一个使用PHP写出来的模板引擎,分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离。使PHP程序员同前端人员分离,使程序员改变程序...
APACHE2.2+MYSQL5.1+PHP5.3+LINUX+SMARTY2.6+JQUERY1.4+CSS3.0常用手册结合。 最近在linux上开发,把所有之前在windows有很多chm手册整理一下。包含了常用的php开发技术包含前端和后端的,和linux教程。希望能够为你...
SpeedPHP 3.1.66是SpeedPHP 3.0正式版的增强版本,对SAE(新浪云计算平台)、新的Smarty 3等有着良好的支持。并增强和改进了多项功能。 SpeedPHP框架系统 v3.1.89 更新: 升级Smarty 3,更稳定 修正了URLREWRITE...
Smarty是一个使用PHP写出来的模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PH
为您提供Smarty下载,Smarty是一个使用PHP写出来的模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离...
计算机后端-整套PHP视频教程.配套工具Smarty-3.1.4.7z
Smarty简介 Smarty是一个使用PHP写出来的模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离。简单的...
Smarty 3.1.35 更新日志:2020-04-14在评论之后删除空格;在arrayiterators上修复foreachelse;修复git导出存档中包含的文件,用于软件包维护人员;为可缓存插件设置缓存属性时抛出SmartyException;修复了用null...
Smarty 开源php项目开发中的模板引擎 v3.1.21.zip
基于PHP的Smarty 开源php项目开发中的模板引擎 v3.1.21.zip