CodeIgniter中使用Smarty3基本配置
一、創(chuàng)建Smarty類庫
1.將smarty的libs文件復(fù)制到libraries下(這里我重命名為smarty)
2.新建Cismarty.php文件。(符合文件規(guī)范,文件名的首字母和class名的首字母大寫,但是控制器引用加載時,類名/文件名不需要大寫)
Cismarty.php
<?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編譯過的所有模板文件的存放目錄地址
}
}
?>
在對應(yīng)目錄新建smarty的文件夾。templates,configs,cache,plugins,templates_c.
二、控制器文件
建立控制器文件paper.php(類名的首字母大寫)(使用load加載libraries時默認(rèn)執(zhí)行構(gòu)造器函數(shù),使用url路由訪問控制器時執(zhí)行構(gòu)造器函數(shù)和默認(rèn)的index方法。)
paper.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');
}
}
?>
也可以在application/config/autoload.php中配置自動加載資源。
相關(guān)文章
用php實現(xiàn)百度網(wǎng)盤圖片直鏈的代碼分享
華為網(wǎng)盤有個直鏈功能,不過需要錢買。我有百度網(wǎng)盤,不過百度的網(wǎng)盤外鏈不能在網(wǎng)頁里直接使用圖片 華為的直鏈功能可以做到。百度哪天也能有這功能就好了。2012-11-11
教你如何用php實現(xiàn)LOL數(shù)據(jù)遠(yuǎn)程獲取
LOL(英雄聯(lián)盟)最近非常的火爆,哥自然也在玩了,最近遇到個問題,就是每次想看看自己的戰(zhàn)斗力啥的,還得先開盒子等等,麻煩,最近有一個想法,打算把它實現(xiàn)出來。2014-06-06
thinkphp循環(huán)結(jié)構(gòu)用法實例
這篇文章主要介紹了thinkphp循環(huán)結(jié)構(gòu)用法,以實例形式講解了for、volist及foreach的用法,是非常實用的技巧,需要的朋友可以參考下2014-11-11

