以插件形式加入smarty.
根据CI的规则。
下载smarty,并将其放到application/libraries/smarty下。
新建Cismarty.php,放在application/libraries下
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
- <?php defined('BASEPATH') or die('Access restricted!');
-
-
-
- require(APPPATH.'libraries/smarty/Smarty.class.php');
- class Cismarty extends Smarty
- {
- public $ext = 'tpl';
- public $dir = '';
- public $layout = 'layout/main';
-
-
-
-
-
-
-
- public function __construct($template_dir = '', $compile_dir = '', $config_dir = '', $cache_dir = '')
- {
- $this->Smarty();
- if(is_array($template_dir)){
- foreach ($template_dir as $key => $value) {
- $this->$key = $value;
- }
- }
- else {
- $this->cache_dir = $cache_dir ? $cache_dir : BASEPATH . 'cache/';
- $this->template_dir = $template_dir ? $template_dir : APPPATH . 'views/';
- $this->compile_dir = $compile_dir ? $compile_dir : APPPATH . 'tpl_c/';
- $this->compile_check = true;
- $this->debugging = false;
- $this->caching = 0;
- $this->cache_lefetime= 6000;
- $this->left_delimiter= '<!--{';
- $this->right_delimiter= '}-->';
- }
- }
-
-
-
-
-
-
- public function show($tpl){
- $this->assign('jsFiles',$this->getJsHtml());
- $this->assign('jsFiles1',$this->getJsHtml(1));
- $this->assign('LAYOUT', $this->dir ? $this->dir.'/'.$tpl.'.'.$this->ext : $tpl.'.'.$this->ext);
- $this->display($this->layout.'.'.$this->ext);
- }
-
-
-
-
-
-
- public function addCss($file) {
- if (strpos($file,'/')==false) {
- $file = config_item('css') . $file;
- }
- $GLOBALS['cssFiles'][$file] = $file;
- }
-
-
-
-
-
-
- public function addJs($file,$btm=NULL) {
- if (strpos($file,'/')==false) {
- $file = config_item('js') . $file;
- }
- if ($btm==NULL) {
- $GLOBALS['jsfiles'][$file] = $file;
- } else {
- $GLOBALS['jsbtmfiles'][$file] = $file;
- }
- }
-
-
-
-
-
- public function getJsHtml($btm=NULL) {
- $html = '';
- if (!$GLOBALS['jsfiles']) {
- return;
- }
- $jsFile = $btm?'jsbtmfiles':'jsfiles';
- if (@$GLOBALS[$jsFile]) {
- foreach ($GLOBALS[$jsFile] as $value) {
- $html .= $this->jsInclude($value,true)."/n";
- }
- return $html;
- } else {
- return ;
- }
- }
-
-
-
-
-
-
-
- public function addTag($tag, $attribute = NULL, $content = NULL) {
- $this->js();
- $html = '';
- $tag = strtolower($tag);
- $html .= '<'.$tag;
- if ($attribute!=NULL) {
- if (is_array($attribute)) {
- foreach ($attribute as $key=>$value) {
- $html .= ' '.strtolower($key).'="'.$value.'"';
- }
- } else {
- $html .= ' '.$attribute;
- }
- }
- if ($content) {
- $html .= '>'.$content.'</'.$tag.'>';
- } else {
- $html .= ' />';
- }
- $this->output .= $html;
- return $html;
- }
-
-
-
-
-
- public function addText($content) {
- $this->js();
- $content = htmlentities($content);
- $this->output .= $content;
- return $content;
- }
-
-
-
-
-
-
- public function js($jscode = NULL, $end = false) {
- if (!$this->inJsArea && $jscode) {
- $this->output .= "/n<mce:script language='JavaScript' type='text/javascript'><!--
- /n
- $this->inJsArea = true;
- }
- if ($jscode==NULL && $this->inJsArea==true) {
- $this->output .= "/n
-
- $this->inJsArea = false;
- } else {
- $this->output .= "/t$jscode/n";
- if ($end) {
- $this->js();
- }
- }
- return;
- }
-
-
-
-
-
-
- public function jsAlert($message, $end = false) {
- $this->js('alert("' . strtr($message, '"', '//"') . '");', $end);
- }
-
-
-
-
-
-
- public function jsInclude($fileName,$return = false, $defer = false) {
- if (!$return) {
- $this->js();
- }
- $html = '<mce:script language="JavaScript" type="text/javascript" src="'
- . $fileName . '" mce_src="'
- . $fileName . '"' . ( ($defer) ? ' defer' : '' )
- . '></mce:script>';
- if (!$return) {
- $this->output .= $html;
- } else {
- return $html;
- }
- }
-
-
-
-
-
- public function cssInclude($fileName,$return = false) {
- if (!$return) {
- $this->js();
- }
- $html = '<LINK href="' . $fileName . '" mce_href="' . $fileName . '" rel=stylesheet>' . chr(13);
- if (!$return) {
- $this->output .= $html;
- } else {
- return $html;
- }
- }
-
-
-
-
-
- public function output($print = false) {
- $this->js();
- if ($print) {
- echo $this->output;
- $this->output = '';
- return;
- } else {
- $output = $this->output;
- $this->output = '';
- return $output;
- }
- }
- }
- ?>
打开配置文件(config/autoload.php)
$autoload['libraries'] = array('cismarty');//加入cismarty
这样在所有应用中,都可以使用$this->cismarty来调用smarty实例了。
Cismarty类已经在原有的smarty::display基础上做了小的改动,已经支持layout功能
默认加载view/layout/main.tpl作为布局文件。
可以通过$this->cismarty->layout = "xxxx"来更改
http://blog.csdn.net/a600423444/article/details/5892726
分享到:
相关推荐
CodeIgniter + Smarty集成 集成验证码 Code Igniter是一个很不错的PHP框架,Smarty是一个非常好的显示层框架,将这两个框架集成安装到一起.
主要介绍了CodeIgniter集成smarty的方法,结合实例形式详细分析了CodeIgniter集成Smarty的具体步骤与相关注意事项,需要的朋友可以参考下
主要介绍了CodeIgniter整合Smarty的方法,结合实例形式分析了CodeIgniter3.0.3整合Smarty3.1.27的步骤与相关设置技巧,需要的朋友可以参考下
Codeigniter框架整合Smarty引擎DEMO
主要介绍了CodeIgniter中使用Smarty3基本配置,本文给出了创建类库的方法和控制器中调用实例,这样就可以完整的使用Smarty了,需要的朋友可以参考下
主要介绍了CodeIgniter框架实现的整合Smarty引擎DEMO,结合实例形式分析了CodeIgniter框架整合Smarty引擎的原理、操作步骤及相关实现技巧,需要的朋友可以参考下
后台管理程序由php开发,目前只实现了基本功能:模块管理... 使用codeigniter框架和Smarty模板 页面使用ACE Admin UI模板,为了结合frame做了二次修改 图形报表使用openflashchart,OFC php有不少BUG,我已经做了修复
netbeans对Codeigniter框架支持的插件,其中包括两个插件。安装方法可以通过搜索Netbeans+PHP+Codeigniter等关键词找到具体的安装方法。
codeigniter 代码实例,基与codeigniter 2.1.4,smarty 3,jquery 1.9开发
主要介绍了Codeigniter中集成smarty和adodb的方法,结合实例形式分析了Codeigniter库的使用技巧,需要的朋友可以参考下
CodeIgniter最新版本,开源、免费、轻量级的web编程,基于MVC的编程架构能大大提高php编码生产力。
PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter...
CodeIgniter框架
php程序设计,web系统源码,源码,数据库MySQL,毕业设计项目,可用于课程设计作业等。
codeigniter 代码实例分享,基于jquery1.4,codeigniter,eclipse 开发
一个简单的Codeigniter用户登录验证例子程序,支持session,密码加密存储,供初学者参考。
描述 :CodeIgniter 便捷开发工具 作者: 51dr.com 开发环境: Win +Delphi 7 +Raize 授权方式:GPL(GNU General Public License)开源软件 程序下载地址: Down 源代码下载地址: 暂缺(服务器空间不支持大文件) ...
本篇文章是对CodeIgniter自定义配置文件进行了详细的分析介绍,需要的朋友参考下