宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

在我们使用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

更多干货:http://www.devdo.net/