设为首页
收藏本站
用户名
Email
自动登录
找回密码
密码
登录
立即注册
只需一步,快速开始
快捷导航
登录
注册
论坛首页
BBS
建站模版
微站设计
虚拟主机
企业邮箱
博客日志
Blog
搜索
搜索
搜索
热搜
长春
优惠
活动
做网站
本版
帖子
用户
本版
帖子
用户
请
登录
后使用快捷导航
没有帐号?
立即注册
道具
勋章
任务
留言板
设置
我的收藏
退出
时时商务社区
»
论坛首页
›
建站资源
›
建站技术
›
CodeIgniter集成smarty的方法详解
返回列表
查看:
840
|
回复:
0
CodeIgniter集成smarty的方法详解
[复制链接]
qz234
当前离线
积分
7694
2588
主题
2588
帖子
7694
积分
论坛元老
论坛元老, 积分 7694, 距离下一级还需 9992305 积分
论坛元老, 积分 7694, 距离下一级还需 9992305 积分
积分
7694
发消息
电梯直达
楼主
发表于 2018-2-14 05:35:41
|
只看该作者
|
倒序浏览
|
阅读模式
本文实例讲述了CodeIgniter集成smarty的方法。分享给大家供大家参考,具体步骤如下:
1.下载smarty
解压到ci的libraries目录 如:
ci/application/libraries/Smarty-2.6.20
2.编写Mysmarty.php 自己的类库文件
代码如下:
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里
补充:小编在这里推荐一款本站的php格式化美化的排版工具帮助大家在以后的PHP程序设计中进行代码排版:
php代码在线格式化美化工具:
http://tools.jb51.net/code/phpformat
另外,由于php属于C语言风格,因此下面这款工具同样可以实现php代码的格式化:
C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json
更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《
codeigniter入门教程
》、《
CI(CodeIgniter)框架进阶教程
》、《
php优秀开发框架总结
》、《
ThinkPHP入门教程
》、《
ThinkPHP常用方法总结
》、《
Zend FrameWork框架入门教程
》、《
php面向对象程序设计入门教程
》、《
php+mysql数据库操作入门教程
》及《
php常见数据库操作技巧汇总
》
希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。
您可能感兴趣的文章:
php之CodeIgniter学习笔记
CI(CodeIgniter)框架配置
CI(CodeIgniter)框架中的增删改查操作
CodeIgniter启用缓存和清除缓存的方法
codeigniter集成ucenter1.6双向通信的解决办法
Codeigniter整合Tank Auth权限类库详解
让codeigniter与swfupload整合的最佳解决方案
CodeIgniter辅助函数helper详解
Codeigniter(CI)框架分页函数及相关知识
CodeIgniter中使用Smarty3基本配置
Codeigniter中集成smarty和adodb的方法
CodeIgniter整合Smarty的方法详解
分享到:
QQ好友和群
QQ空间
腾讯微博
腾讯朋友
收藏
0
回复
使用道具
举报
返回列表
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
本版积分规则
发表回复
回帖后跳转到最后一页
用户反馈
客户端