[轉]PHPCMS V9添加模板自定義全局變量


在我們使用PHPCMS V9的制作網站模板的時候,使用全局模板變量能輕松調用,使用起來非常方便,而且可以統一修改,方便維護。

下面就來講一下在PHPCMS V9中如何添加自定義全局變量。

修改網站system.php配置文件

文件路徑:/caches/configs/system.php

在第30行左右,

'app_path' => 'http://127.0.0.1/weiyun_new/',//動態域名配置地址

 

在此行下添加配置,我這里是一個qq咨詢的地址,結果如下:

'app_path' => 'http://127.0.0.1/weiyun_new/',//動態域名配置地址
'chat_path' => 'tencent://message/?uin=343326675&Site=宜賓微雲網絡&Menu=yes', //咨詢地址

修改網站base.php配置文件

文件路徑:/phpcms/base.php

在第51行左右,

define('APP_PATH',pc_base::load_config('system','app_path'));

  

在此行下添加配置如下:

//動態程序路徑
define('APP_PATH',pc_base::load_config('system','app_path'));
//咨詢路徑
define('CHAT_PATH',pc_base::load_config('system','chat_path'));

  

到這一步之后,就已經可以在模板中調用了,調用方法{CHAT_PATH},模板自動解析。

為了方便以后修改修護,不用每次都去改代碼,我們去修改一下后台模板來實現。

PHPCMS V9添加模板自定義全局變量 - 第1張  | 碼農小兵

修改網站setting.tpl.php文件

文件路徑:/phpcms/modules/admin/templates/setting.tpl.php

在第73行左右,

<tr>
<th width="120"><?php echo L('setting_upload_url')?></th>
<td class="y-bg"><input type="text" class="input-text" name="setconfig[upload_url]" id="upload_url" size="50" value="<?php echo $upload_url?>" /></td>
</tr>

  

在此行下添加配置如下:

<tr>
<th width="120"><?php echo L('setting_upload_url')?></th>
<td class="y-bg"><input type="text" class="input-text" name="setconfig[upload_url]" id="upload_url" size="50" value="<?php echo $upload_url?>" /></td>
</tr>
<tr>
<th width="120"><?php echo L('setting_chat_path')?></th>
<td class="y-bg"><input type="text" class="input-text" name="setconfig[chat_path]" id="chat_path" size="50" value="<?php echo $chat_path?>" /></td>
</tr>

  

修改網站admin.lang.php文件,添加語言包

文件路徑:/phpcms/languages/zh-cn/admin.lang.php

在第170行左右,

$LANG['setting_upload_url'] = '附件URL訪問路徑';

  

在此行下添加配置如下:

$LANG['setting_upload_url'] = '附件URL訪問路徑';
$LANG['setting_chat_path'] = '咨詢地址';

  

修改global.func.php文件set_config函數

文件路徑:/phpcms/languages/zh-cn/admin.lang.php

在第42行左右,在’img_path’后面添加’chat_path’,這樣才能保存設置

if(in_array($k,array('js_path','css_path','img_path','attachment_stat','admin_log','gzip','errorlog','phpsso','phpsso_appid','phpsso_api_url','phpsso_auth_key','phpsso_version','connect_enable', 'upload_url','sina_akey', 'sina_skey', 'snda_enable', 'snda_status', 'snda_akey', 'snda_skey', 'qq_akey', 'qq_skey','qq_appid','qq_appkey','qq_callback','admin_url'))) {

  

修改后結果如下:

if(in_array($k,array('js_path','css_path','img_path','chat_path','attachment_stat','admin_log','gzip','errorlog','phpsso','phpsso_appid','phpsso_api_url','phpsso_auth_key','phpsso_version','connect_enable', 'upload_url','sina_akey', 'sina_skey', 'snda_enable', 'snda_status', 'snda_akey', 'snda_skey', 'qq_akey', 'qq_skey','qq_appid','qq_appkey','qq_callback','admin_url'))) {

PHPCMS V9中添加自定義全局變量就是這么添加的,它的優點是方便維護,缺點是要修改幾個文件,在更新PHPCMS V9時可能會被替換,如果被替換就需要重新來一遍。

轉載地址:http://www.devdo.net/phpcmsv9-setting-variable.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM