您好,登錄后才能下訂單哦!
切換到ci路徑下
在application/libraries創建smarty文件夾,并將解壓好的Smarty庫中的libs文件夾復制到Smarty文件夾中
在application/config下創建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下創建一個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');
}
}
打開application/config/autoload.php 修改
$autoload['libraries'] = array('');
改為
$autoload['libraries'] = array('Ci_Smarty');
在application/core下新建一個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下創建templates目錄
在templates下新建一個測試模板test.tpl
hello.world
在controllers下新建一個測試文件Pages.php繼承MY_controller
<?php
class Pages extends MY_controller {
public function index()
{
$this->display('test.tpl');
}
}
至此完成
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。