CI整合Smarty,cismarty
1.到相應的網站下載smarty模板;
2.將原始碼中的libs目錄複寫到項目的libraries目錄下,改名為smarty3.0
3.在項目目錄的libraries檔案夾內建立檔案ci_smarty.php,裡面的內容如下:
defined('BASEPATH') OR exit('No direct script access allowed');
require_once(APPPATH . 'libraries/smarty3.0/Smarty.class.php');
class ci_smarty extends Smarty
{
protected $ci;
public function __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');
}
}
4.在項目目錄的config檔案夾內建立檔案smarty.php檔案,裡面的內容如下:
5.在入口檔案所在目錄建立檔案夾templates_c
6.在項目的設定檔夾下,autoload.php檔案中加入
$autoload['libraries'] = array('ci_smarty');
7.在項目目錄的core檔案夾中建立檔案MY_Controller.php 內容如下: // 擴充核心控制類
8.測試
控制器中
視圖中
http://www.bkjia.com/PHPjc/1064066.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1064066.htmlTechArticleCI整合Smarty,cismarty 1.到相應的網站下載smarty模板; 2.將原始碼中的libs目錄複寫到項目的libraries目錄下,改名為smarty3.0 3.在項目目錄的libr...