给新伙伴的忠告:不要去想着有多复杂,看一遍绝对就会弄了!

这样集成的目的是什么?

因为我使用过CI和smarty,所以我就按自己的理解讲一下:CI框架在控制器、models方面做的很好,但在多变的视图方面我感觉没有专门处理视图的smarty模板做的好,因此就想到了将这两者合并,各取其长。

1、下载CI框架、smarty模板,这个就不需要我多说了。

2、将smarty的libs文件夹copy到CI的third_party文件夹下(其实copy到哪个文件夹下是无所谓的,只要加载到它就行了),并更名为smarty;

3、在CI的根目录下创建一下文件夹:

还有,在CI的helpers文件夹下创建smartyPLU文件夹

4、在CI的配置文件夹config下创建smarty.php配置文件,并拷入以下代码:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

//指定相关的文件夹
$config['template_dir'] = APPPATH . 'views';
$config['compile_dir'] = FCPATH . 'templates_c';
$config['config_dir'] = FCPATH . 'configs';
$config['cache_dir'] = FCPATH . 'cache';
$config['plugins_dir'] = APPPATH . 'helpers/smartyPLU'; //$config['template_ext'] = ; //设置缓存,默认为false
$config['caching'] = false;
$config['cache_lifetime'] = 60; $config['auto_literal'] = false; $config['left_delimiter'] = '<{';
$config['right_delimiter'] = '}>';

5、在CI的libraries文件夹中创建CSmarty.php文件,并拷入以下代码:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

require_once(APPPATH.'third_party/smarty/Smarty.class.php');     //这里指定Smarty.class.php的存放位置

class CSmarty extends Smarty
{ protected $CI; public function __construct(){ $this->CI = & get_instance();
$this->CI->load->config('smarty'); //这里加载smarty的配置信息的文件 //相关配置项
$this->template_dir = $this->CI->config->item('template_dir');
$this->compile_dir = $this->CI->config->item('compile_dir');
$this->config_dir = $this->CI->config->item('config_dir');
$this->cache_dir = $this->CI->config->item('cache_dir');
$this->plugins_dir = $this->CI->config->item('plugins_dir');
//$this->template_ext = $this->CI->config->item('template_ext'); $this->caching = $this->CI->config->item('caching');
$this->cache_lifetime = $this->CI->config->item('cache_lifetime'); $this->auto_literal = $this->CI->config->item('auto_literal'); $this->left_delimiter = $this->CI->config->item('left_delimiter');
$this->right_delimiter = $this->CI->config->item('right_delimiter'); //设置编码格式和时区
header("Content-type:text/html;charset=utf-8");
date_default_timezone_set('UTC');
}
}

6、将smarty的启动加到CI的自启动文件autoload.php文件中:

$autoload['libraries'] = array('CSmarty');

7、接下来就是在CI中使用了,将CI中的通过$this->load->view("index",$data)方式加载视图改为smarty方式:

$this->csmarty->assign('data', $data);
$this->csmarty->display('index.html');

PS:使用了smarty的方式时,会出现一些路径上的问题。

CI集成Smarty的实现方式的更多相关文章

  1. **【ci框架】PHP的CI框架集成Smarty的最佳方式

    因为CI自带的模板功能不是很方便,所以大家普遍采用集成Smarty的方式来弥补CI这方面的不足. 本人在网上看了不少CI集成Smarty的教程,包括咱们CI论坛里面的一个精华帖子 http://cod ...

  2. Gitlab CI 集成 Kubernetes 集群部署 Spring Boot 项目

    在上一篇博客中,我们成功将 Gitlab CI 部署到了 Docker 中去,成功创建了 Gitlab CI Pipline 来执行 CI/CD 任务.那么这篇文章我们更进一步,将它集成到 K8s 集 ...

  3. 星云测试插装编译流程与CI集成

    星云测试Horn插装采用脚本配置方式自动对语法进行扫描和插装,在整个插装过程中需要用到星云提供的插件工具.通过与CI集成,在CI编译前通过jenkins调用星云插装插件模块进行必要的数据填充,生成对应 ...

  4. Atitit.你这些项目不都是模板吗?不是原创  集成和整合的方式大总结

    Atitit.你这些项目不都是模板吗?不是原创  集成和整合的方式大总结 1.1. 乔布斯的名言:创新即整合(Creativity is just connecting things).1 1.2. ...

  5. Yii集成smarty说明

    1.       [在protected目录下建立文件夹vendor/smarty,把smarty的类包放入其中] 2.       [在extensions目录下边建立文件CSmarty.php] ...

  6. CI集成phpunit Error: No code coverage driver is available 的解决

    CI集成phpunit时,运行报No code coverage driver is available的错误,如下图: yanglingdeMacBook-Pro:tests yangling$ p ...

  7. CI集成 mesos 资源分配的思考, 待续

    读了mesos的论文(https://people.eecs.berkeley.edu/~alig/papers/mesos.pdf ),感觉应用在 CI 上的资源管理很赞,能够解决 jenkins在 ...

  8. Jenkins+Git+Fastlane+Fir CI集成

    上一篇有讲关于fastlane自动化部署,本篇将会着重讲关于fastlane的实际应用. 目标: 利用自动化jenkins打包工具,自动拉取git仓库代码 不需要通过手动检查修改xcode中项目配置修 ...

  9. 解析SparkStreaming和Kafka集成的两种方式

    spark streaming是基于微批处理的流式计算引擎,通常是利用spark core或者spark core与spark sql一起来处理数据.在企业实时处理架构中,通常将spark strea ...

随机推荐

  1. vue+axios请求头封装

    import { mapMutations } from 'vuex' import axios from 'axios' import { Toast } from 'mint-ui'; impor ...

  2. C# 基础 字符串 集合 文件操作

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. Samba Server 的使用者帳號及密碼備份

    Samba Server 自從 3.x 後改成使用 tdbsam 的方式來管理使用者的帳號及密碼,原本的帳號密碼都是存放在 /etc/samba 目錄之下,最近要做備份時,一時之間竟然找不到 Samb ...

  4. javascript 元编程之 method_missing

    javascript 元编程之 method_missing 引言 要说元编程 ruby 中技巧太多了,今天来写的这个技术也来自于 ruby 中的灵感. method_missing 这个在 ruby ...

  5. Bootstrap常用的自带插件

    Bootstrap自带的那些常用插件. 模态框 模态框的HTML代码放置的位置 务必将模态框的HTML代码放在文档的最高层级内(也就是说,尽量作为 body 标签的直接子元素),以避免其他组件影响模态 ...

  6. 4.3. Scrapy Shell

    Scrapy Shell:模拟scrapy去发送请求 Scrapy终端是一个交互终端,我们可以在未启动spider的情况下尝试及调试代码,也可以用来测试XPath或CSS表达式,查看他们的工作方式,方 ...

  7. Git学习笔记(2)-Eclipse中Git插件使用

    目前我使用的Eclipse luna版本中已经集成了git插件,这里就不介绍如何安装Git插件了,不懂可以看其他的博客. 上篇笔记介绍了Git的基本指令,实际开发中我基本都使用eclipse插件进行代 ...

  8. pgsql 相关函数

    1.COALESCE — 空值替换函数.示例:COALESCE(col, 'replacement') :如果col列的值为null,则col的值将被替换为'replacement' 2.regexp ...

  9. 201271050130-滕江南-《面向对象程序设计(java)》第十七周学习总结

    201271050130-滕江南-<面向对象程序设计(java)>第十七周学习总结 博文正文开头格式:(2分) 项目 内容 这个作业属于哪个课程 https://www.cnblogs.c ...

  10. CSS基础学习-6.CSS属性_列表、表格