CI框架集成Smarty
Posted 王大西
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 { protected $ci; protected $template_ext; protected $complie_dir; public function __construct(){ parent::__construct(); $this->ci = & get_instance(); $this->ci->load->config(‘smarty‘);//加载smarty的配置文件 //获取相关的配置项 $this->template_dir = $this->ci->config->item(‘template_dir‘); $this->complie_dir = $this->ci->config->item(‘compile_dir‘); $this->cache_dir = $this->ci->config->item(‘cache_dir‘); $this->config_dir = $this->ci->config->item(‘config_dir‘); $this->template_ext = $this->ci->config->item(‘template_ext‘); $this->caching = $this->ci->config->item(‘caching‘); $this->cache_lifetime = $this->ci->config->item(‘lefttime‘); $this->left_delimiter = ‘<{‘; $this->right_delimiter = ‘}>‘; } }
3.在项目目录的config文件夹内新建文件smarty.php文件,里面的内容如下:
<?php if ( ! defined(‘BASEPATH‘)) exit(‘No direct script access allowed‘); $config[‘theme‘] = ‘default‘; $config[‘template_dir‘] = APPPATH . ‘views‘; $config[‘compile_dir‘] = FCPATH . ‘templates_c‘; $config[‘cache_dir‘] = FCPATH . ‘cache‘; $config[‘config_dir‘] = FCPATH . ‘configs‘; $config[‘template_ext‘] = ‘.html‘; $config[‘caching‘] = false; $config[‘lefttime‘] = 60;
4.在入口文件所在目录新建文件夹templates_c、cache、configs;
5.在项目目录下面的config目录中找到autoload.php文件
$autoload[‘libraries‘] = array(‘Cismarty‘);
6.在项目目录的core文件夹中新建文件MY_Controller.php 内容如下:
<?php if (!defined(‘BASEPATH‘)) exit(‘No direct access allowed‘); class MY_Controller extends CI_Controller { public function __construct() { parent::__construct(); } public function assign($key,$val) { $this->cismarty->assign($key,$val); } public function display($html) { $this->cismarty->display($html); } }
以上,配置完毕。
以上是关于CI框架集成Smarty的主要内容,如果未能解决你的问题,请参考以下文章