码迷,mamicode.com
首页 > 其他好文 > 详细

CI框架集成Smarty

时间:2016-04-06 18:20:48      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/hejun695/p/5360053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!