zoukankan      html  css  js  c++  java
  • 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);
        }
    }

    以上,配置完毕。

     

  • 相关阅读:
    门禁控制系统的状态机-《实时控制软件设计》第二周作业
    [leetcode] Single Number
    [leetcode] Candy
    [leetcode] Gas Station
    [leetcode] Clone Graph
    [leetcode] Palindrome Partitioning II
    [leetcode] Palindrome Partitioning
    [leetcode] Surrounded Regions
    [leetcode] Sum Root to Leaf Numbers
    [leetcode] Longest Consecutive Sequence
  • 原文地址:https://www.cnblogs.com/hejun695/p/5360053.html
Copyright © 2011-2022 走看看