您好,登錄后才能下訂單哦!
切換到ci路徑下
在application/libraries創(chuàng)建smarty文件夾,并將解壓好的Smarty庫(kù)中的libs文件夾復(fù)制到Smarty文件夾中
在application/config下創(chuàng)建smarty.php, 代碼如下:
<?php
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
$config['cache_lifetime'] = 60;
$config['caching'] = false;
$config['template_dir'] = APPPATH . 'views/templates';
$config['compile_dir'] = APPPATH . 'views/templates_c';
$config['cache_dir'] = APPPATH . 'views/cache';
$config['config_dir'] = APPPATH . 'views/config';
$config['use_sub_dirs'] = false;
//子目錄變量(是否在緩存文件夾中生成子目錄)
$config['left_delimiter'] = '{';
$config['right_delimiter'] = '}';
在application/libraries下創(chuàng)建一個(gè)Ci_Smarty.php,代碼如下
<?php
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
require_once APPPATH.'libraries/smarty/libs/Smarty.class.php';
class Ci_Smarty extends Smarty
{
protected $ci;
public function __construct()
{
parent::__construct();
$this -> ci =& get_instance();
$this -> ci -> load -> config('smarty');
//加載smarty的配置文件
$this -> cache_lifetime = $this -> ci -> config -> item('cache_lifetime');
$this -> caching = $this -> ci -> config -> item('caching');
$this -> config_dir = $this -> ci -> config -> item('config_dir');
$this -> template_dir = $this -> ci -> config -> item('template_dir');
$this -> compile_dir = $this -> ci -> config -> item('compile_dir');
$this -> cache_dir = $this -> ci -> config -> item('cache_dir');
$this -> use_sub_dirs = $this -> ci -> config -> item('use_sub_dirs');
$this -> left_delimiter = $this -> ci -> config -> item('left_delimiter');
$this -> right_delimiter = $this -> ci -> config -> item('right_delimiter');
}
}
打開(kāi)application/config/autoload.php 修改
$autoload['libraries'] = array('');
改為
$autoload['libraries'] = array('Ci_Smarty');
在application/core下新建一個(gè)MY_Controller.php ,代碼如下:
<?php
class MY_controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function assign($key, $val)
{
$this->ci_smarty->assign($key, $val);
}
public function display($html)
{
$this->ci_smarty->display($html);
}
}
在views下創(chuàng)建templates目錄
在templates下新建一個(gè)測(cè)試模板test.tpl
hello.world
在controllers下新建一個(gè)測(cè)試文件Pages.php繼承MY_controller
<?php
class Pages extends MY_controller {
public function index()
{
$this->display('test.tpl');
}
}
至此完成
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。