codeIgniter集成smarty
来源:互联网 发布:模糊车牌识别软件 编辑:程序博客网 时间:2024/05/16 00:58
这几天看了看codeIgniter 挺不错的 mvc模式 之前没用过 这次打算尝试下
但是它的view感觉不如smarty 所以网上找了些帖子 把smarty集成进来用
1.下载smarty
解压到ci的libraries目录 如: ci/application/libraries/Smarty-2.6.20
2.编写Mysmarty.php 自己的类库文件
代码如下:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require "Smarty-2.6.20/libs/Smarty.class.php";
/**
* @file system/application/libraries/Mysmarty.php
*/
class Mysmarty extends Smarty
{
function Mysmarty()
{
$this->Smarty();
$config =& get_config();
// absolute path prevents "template not found" errors
$this->template_dir = (!empty($config['smarty_template_dir']) ? $config['smarty_template_dir'] : BASEPATH . 'application/views/');
$this->compile_dir = (!empty($config['smarty_compile_dir']) ? $config['smarty_compile_dir'] : BASEPATH . 'cache/');
//use CI's cache folder
if (function_exists('site_url')) {
// URL helper required
$this->assign("site_url", site_url()); // so we can get the full path to CI easily
}
}
/**
* @param $resource_name string
* @param $params array holds params that will be passed to the template
* @desc loads the template
*/
function view($resource_name, $params = array()) {
if (strpos($resource_name, '.') === false) {
$resource_name .= '.html';
}
if (is_array($params) && count($params)) {
foreach ($params as $key => $value) {
$this->assign($key, $value);
}
}
// check if the template file exists.
if (!is_file($this->template_dir . $resource_name)) {
show_error("template: [$resource_name] cannot be found.");
}
return parent::display($resource_name);
}
} // END class smarty_library
?>
3.在autoload.php让ci自动加载smarty
$autoload['libraries'] = array('database', 'mysmarty');
或者 使用模板时再自己加载smarty
$this->load->library("mysmarty");
4.smarty变量赋值 display模板
$this->mysmarty->assign('test', 'Hello World.');
$this->mysmarty->view('smarty');
注:images css 等外部资源文件 放在ci系统文件夹外 网站根目录下
最好用
$this->load->helper('url');
base_url()来访问
base_url()."images/xxx.jpg"
不要放到system里
参考网页:
http://devcha.blogspot.com/2007/12/smarty-as-template-engine-in-code.html
示例来自:
http://funcs.org/downloads/code-igniter/code-igniter-smarty-2.zip
但是它的view感觉不如smarty 所以网上找了些帖子 把smarty集成进来用
1.下载smarty
解压到ci的libraries目录 如: ci/application/libraries/Smarty-2.6.20
2.编写Mysmarty.php 自己的类库文件
代码如下:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require "Smarty-2.6.20/libs/Smarty.class.php";
/**
* @file system/application/libraries/Mysmarty.php
*/
class Mysmarty extends Smarty
{
function Mysmarty()
{
$this->Smarty();
$config =& get_config();
// absolute path prevents "template not found" errors
$this->template_dir = (!empty($config['smarty_template_dir']) ? $config['smarty_template_dir'] : BASEPATH . 'application/views/');
$this->compile_dir = (!empty($config['smarty_compile_dir']) ? $config['smarty_compile_dir'] : BASEPATH . 'cache/');
//use CI's cache folder
if (function_exists('site_url')) {
// URL helper required
$this->assign("site_url", site_url()); // so we can get the full path to CI easily
}
}
/**
* @param $resource_name string
* @param $params array holds params that will be passed to the template
* @desc loads the template
*/
function view($resource_name, $params = array()) {
if (strpos($resource_name, '.') === false) {
$resource_name .= '.html';
}
if (is_array($params) && count($params)) {
foreach ($params as $key => $value) {
$this->assign($key, $value);
}
}
// check if the template file exists.
if (!is_file($this->template_dir . $resource_name)) {
show_error("template: [$resource_name] cannot be found.");
}
return parent::display($resource_name);
}
} // END class smarty_library
?>
3.在autoload.php让ci自动加载smarty
$autoload['libraries'] = array('database', 'mysmarty');
或者 使用模板时再自己加载smarty
$this->load->library("mysmarty");
4.smarty变量赋值 display模板
$this->mysmarty->assign('test', 'Hello World.');
$this->mysmarty->view('smarty');
注:images css 等外部资源文件 放在ci系统文件夹外 网站根目录下
最好用
$this->load->helper('url');
base_url()来访问
base_url()."images/xxx.jpg"
不要放到system里
参考网页:
http://devcha.blogspot.com/2007/12/smarty-as-template-engine-in-code.html
示例来自:
http://funcs.org/downloads/code-igniter/code-igniter-smarty-2.zip
- codeIgniter集成smarty
- CodeIgniter集成Smarty
- codeigniter框架集成smarty的方法
- 在 CodeIgniter 2中集成 Smarty 3 模板引擎
- CodeIgniter整合smarty
- CodeIgniter,smarty的使用
- Codeigniter整合smarty
- Codeigniter轻松整合smarty
- Codeigniter集成PHPExcel
- 为 CodeIgniter 增加第三方类库-smarty
- CodeIgniter支持smarty,并配置支持layout
- Codeigniter框架整合Smarty引擎DEMO
- cakephp: 和Smarty集成
- cakephp: 和Smarty集成
- CodeIgniter 和淘宝SDK 集成
- Smarty 下前后台集成
- zend framework2 集成 smarty 资料
- Codeigniter使用Smarty模板引擎之安装方法
- ASP.NET保持用户状态的九种选择
- Oracle 恢复测试-控制文件篇(二)
- 关于同时启动两个tomcat服务器的问题的整理(转)
- 用bjam构建boost-1.36
- asp.net2.0基于flex3.0的ajax登录验证(MXML和XML)
- codeIgniter集成smarty
- asp.net 配置文件对app_code中的类型引用
- java 杨辉三角代码
- vsftpd 'can not change directory' error
- 二叉树的非递归遍历(使用栈)
- 查找随机数组中的质数个数
- IBM Rational 系统开发最佳实践工具包
- 精通用Grails实现面向资源服务的架构
- Linux 上的云计算平台和应用