《PHP教程:CodeIgniter中使用Smarty3基本配置》要點:
本文介紹了PHP教程:CodeIgniter中使用Smarty3基本配置,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP應(yīng)用一、創(chuàng)立Smarty類庫
PHP應(yīng)用1.將smarty的libs文件復(fù)制到libraries下(這里我重命名為smarty)
2.新建Cismarty.php文件.(符合文件規(guī)范,文件名的首字母和class名的首字母大寫,但是控制器引用加載時,類名/文件名不必要大寫)
PHP利用Cismarty.php
PHP應(yīng)用
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
require(APPPATH . 'libraries/smarty/Smarty.class.php');
//CI,文件系統(tǒng)全用相對路徑相對index.php所在的路徑,url全部用絕對路徑.
//BASEPATH - The full server path to the "system" folder
//APPPATH - The full server path to the "application" folder
class Cismarty extends Smarty
{
public function __construct()
{
parent::__construct();
$this->caching = false;
$this->setTemplateDir(APPPATH . 'views/Smarty/templates'); //設(shè)定所有模板文件都必要放置的目錄地址.
$this->setConfigDir(APPPATH . 'views/Smarty/configs'); //設(shè)定用于存放模板特殊配置文件的目錄,
$this->setCacheDir(APPPATH . 'views/Smarty/cache'); //在啟動緩存特性的情況下,這個屬性所指定的目錄中放置Smarty緩存的所有模板
$this->setPluginsDir(APPPATH . 'views/Smarty/plugins'); //插件目錄
$this->setCompileDir(APPPATH . 'views/Smarty/templates_c'); //設(shè)定Smarty編譯過的所有模板文件的存放目錄地址
}
}
?>
PHP應(yīng)用?在對應(yīng)目錄新建smarty的文件夾.templates,configs,cache,plugins,templates_c.
PHP應(yīng)用二、節(jié)制器文件
PHP應(yīng)用建立控制器文件paper.php(類名的首字母大寫)(使用load加載libraries時默認執(zhí)行構(gòu)造器函數(shù),使用url路由拜訪控制器時執(zhí)行構(gòu)造器函數(shù)和默認的index方法.)
paper.php:
PHP利用
<?php
class Paper extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function pri_body()
{
$this->load->library('cismarty');
$this->cismarty->assign("name", 1200);
$this->cismarty->display('dd.tpl');
}
}
?>
PHP利用?也可以在application/config/autoload.php中配置自動加載資源.
《PHP教程:CodeIgniter中使用Smarty3基本配置》是否對您有啟發(fā),歡迎查看更多與《PHP教程:CodeIgniter中使用Smarty3基本配置》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/10030.html