日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php smart模板,vaphp整合smart模板有关问题

發(fā)布時間:2025/3/15 php 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php smart模板,vaphp整合smart模板有关问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

vaphp整合smart模板問題

目前正在做一個小項(xiàng)目,選擇Ci框架也是第一次使用,發(fā)現(xiàn)CI沒有內(nèi)置的模版引擎,傳統(tǒng)的php、html混寫有點(diǎn)不習(xí)慣咯被慣壞了,決定將smarty模版引擎整合到CI框架中。

步驟如下:

下載:ci,smarty

配署ci?在這里就不多說了……

1.??將下載好的smarty包的lib文件上傳到ci中的libraries?文件中,將取名稱修改為smarty,在libraries文件新建cismarty.php文件,內(nèi)容如下:

if?(!defined('BASEPATH'))?exit("no?direct?script?access?allowd");

//以下是加載smarty的類文件

require_once(APPPATH.'libraries/smarty/Smarty.class.php');

//定義cismarty類,繼承smarty類

class?cismarty?extends?Smarty{

//定義一個受保護(hù)的變量,

protected?$ci;

function?__construct(){

parent::__construct();

//引用實(shí)例化CI,這里主要是將smarty的配置文件寫到ci中,以方便程序管理

$this->ci?=?&?get_instance();

//加載ci的新建的smarty配置文件

$this->ci->load->config('smarty');

$this->cache_lifetime??=?$this->ci->config->item('cache_lifetime');

$this->caching?????????=?$this->ci->config->item('caching');

$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');

2.??在config下新建smarty.php配置文件

$config['cache_lifetime']?????=?????30*24*3600;?//更新周期

$config['caching']?????????????=?????false;//是否使用緩存,項(xiàng)目在調(diào)試期間,不建議啟用緩存

$config['template_dir']????????=?????APPPATH.'views';?//設(shè)置模板目錄

$config['compile_dir']?????????=?????APPPATH.'views/template_c';?//設(shè)置編譯目錄

$config['cache_dir']?????????=?????APPPATH.'views/cache';//緩存文件夾

$config['use_sub_dirs']?????=?????true;???//子目錄變量(是否在緩存文件夾中生成子目錄)

$config['left_delimiter']?????=?????'

$config['right_delimiter']?????=?????'}>';

3.??在CI里重載smarty的?assign?和?display方法

在框架根目錄下core/目錄下新建控制器繼承CI基類,MY_Controller

class?MY_Controller?extends?CI_Controller?{

public?function?__construct()?{

parent::__construct();

}

public?function?assign($key,$val)?{

$this->cismarty->assign($key,$val);

}

public?function?display($html)?{

$this->cismarty->display($html);

}

}

4.??修改Config文件下的autoload.php?自動加載類文件

$autoload['libraries']?=?array('cismarty');

到此配置已完成.

第3步要在core文件夾下建MY_Controller,但是vsphp創(chuàng)建的CI框架里面沒有這個文件夾,我自己建了個core文件夾在里面創(chuàng)建了MY_Controller。運(yùn)行的時候報錯找不到MY_Controller類。然后我在用到這個類的地方引用這個文件就好了。但是這樣太麻煩了每個文件都要引用。有沒有別的處理方法。

------解決方案--------------------

查找包含?__autoload?或?spl_autoload_register?字樣的文件

修改相關(guān)代碼

------解決方案--------------------

沒定義一個類?你讓他繼承這個MY_Controller類就可以了啊

------解決方案--------------------

在index文件中?默認(rèn)就加載這個文件

總結(jié)

以上是生活随笔為你收集整理的php smart模板,vaphp整合smart模板有关问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。