CI集成Smarty的实现方式

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

这样集成的目的是什么?

因为我使用过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的方式时,会出现一些路径上的问题。

时间: 2024-10-11 05:47:50

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

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

因为CI自带的模板功能不是很方便,所以大家普遍采用集成Smarty的方式来弥补CI这方面的不足. 本人在网上看了不少CI集成Smarty的教程,包括咱们CI论坛里面的一个精华帖子 http://codeigniter.org.cn/forums/forum.php?mod=viewthread&tid=10345. 自己对比了一下这些教程,我认为下面这个方案是所有里面最优秀的,强烈推荐给大家(当然也是我自己采取的方案) 出处: http://www.cnmiss.cn/?p=261 原文里面的一

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

星云测试Horn插装采用脚本配置方式自动对语法进行扫描和插装,在整个插装过程中需要用到星云提供的插件工具.通过与CI集成,在CI编译前通过jenkins调用星云插装插件模块进行必要的数据填充,生成对应的项目插装脚本,即可以通过星云插装插件进行项目插装与编译. 通过星云插件脚本自动创建工程和代码插装 1.解压星云提供的插件包 星云测试在windows环境下提供的插装工具为javaForWindows工具包:将javaForWindows放到合适目录下并解压即可.(LINUX使用LINUX插件包).

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

Atitit.你这些项目不都是模板吗?不是原创  集成和整合的方式大总结 1.1. 乔布斯的名言:创新即整合(Creativity is just connecting things).1 1.2. 腾讯的微创新1 2. 那么软件系统集成和整合的方式常见的有哪些呢? 1 2.1. 一.软件系统功能完全融合在一个系统中2 2.2. 软件系统间以接口方式相互调用2 2.3. 直接访问数据库不是最好的解决方案2 2.4. Gui2 2.5. cli2 2.6. Sso单点登录2 企业在信息化的过程中会

CI框架集成Smarty

1.下载smarty源码包,解压放置于项目目录 libriaries中 2.在libraries中建立Cismarty.php ,填写如下代码 <?php if(!defined('BASEPATH')) EXIT('No direct script asscess allowed'); require_once( APPPATH . 'libraries/smarty-3.1.27/Smarty.class.php' ); class Cismarty extends Smarty { pro

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

在上一篇博客中,我们成功将 Gitlab CI 部署到了 Docker 中去,成功创建了 Gitlab CI Pipline 来执行 CI/CD 任务.那么这篇文章我们更进一步,将它集成到 K8s 集群中去.这个才是我们最终的目标.众所周知,k8s 是目前最火的容器编排项目,很多公司都使用它来构建和管理自己容器集群,可以用来做机器学习训练以及 DevOps 等一系列的事情. 在这里,我们聚焦 CI/CD,针对于 Spring Boot 项目,借助 Gitlab CI 完成流水线的任务配置,最终部

smarty、smarty格式化、smarty整数、smarty float、smarty各种转换方式、smarty日期转换等等 (转)

<? require("setup.php"); define('PAGETITLE','pagtitle'); function insert_top($lid,$sid) { echo "insert function"; } $smarty=new SmartyRebuild(); $smarty->assign('name','Linux'); $smarty->assign('title','在线有有要有和蔼是是非非要要'); $smar

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

读了mesos的论文(https://people.eecs.berkeley.edu/~alig/papers/mesos.pdf ),感觉应用在 CI 上的资源管理很赞,能够解决 jenkins在构建中,分配 executor 以及 executor 在building 的时候 hang 的问题,所以装了一个来试一下. 首先是先装 mesos 了,官网 1.3.0 rpm -Uvh http://repos.mesosphere.com/el/6/noarch/RPMS/mesosphere

Spring集成Memcached三种方式(一)

转载:http://blog.csdn.net/u013725455/article/details/52102170 Memcached Client目前有3种: Memcached Client for Java SpyMemcached XMemcached 这三种Client一直存在各种争议: Memcached Client for Java 比 SpyMemcached更稳定.更早.更广泛: SpyMemcached 比 Memcached Client for Java更高效: X

ci 集成redis

希望在CI中使用redis作为缓存驱动,发现官方github上已经有了,貌似要到3.0才正式发布,先用上吧,省事了 为了保持框架可升级操作如下 1.将system\libraries\Cache\Cache.php复制为application\libraries\Cache\Cache.php 增加配置 protected $valid_drivers = array(     'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy'