5

PHPCMS V9新增自定义全局变量,模版统一调用与修改

 2 years ago
source link: https://blog.qiaohewei.cc/2022/02/13/phpcmsv9_add_global_variable/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
1639043627-11614406329-update_info.jpg

在使用PHPCMS 制作网站时候,如果使用全局模板变量就能轻松调用,而且可以统一修改,方便维护,PHPCMS官方版不支持后台新增全局变量,本文讲解如何添加自定义全局变量。

一、系统配置修改

修改网站配置文件system.php

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

搜索'app_path',在动态域名配置地址下面添加新的配置,以下以新增一个URL地址为例

'app_path' => '',//动态域名配置地址
'newurl_path' => 'https://blog.qiaohewei.cc', //新增的网站地址
'app_path' => '',//动态域名配置地址
'newurl_path' => 'https://blog.qiaohewei.cc', //新增的网站地址

修改网站配置文件base.php

文件路径:/phpcms/base.php

在‘define('APP_PATH',pc_base::load_config('system','app_path'));’此行下面增加新的配置

//动态程序路径
define('APP_PATH',pc_base::load_config('system','app_path'));
//新的URL全局变量配置
define('NEWURL_PATH',pc_base::load_config('system','newurl_path'));
//动态程序路径
define('APP_PATH',pc_base::load_config('system','app_path'));
//新的URL全局变量配置
define('NEWURL_PATH',pc_base::load_config('system','newurl_path'));

注意代码大小写以及对应情况,避免与默认全局变量相同,如此我们便可以在模版文件中调用了,调用方式为{NEWURL_PATH}

二、后台修改

为了尽可能的方便维护全局变量,我们可以修改后台模版,如此便可以在后台修改变量的值

修改网站setting.tpl.php文件

文件路径:/phpcms/modules/admin/templates/setting.tpl.php ,第73han行左右

<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_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_newurl_path')?></th>
<td class="y-bg"><input type="text" class="input-text" name="setconfig[newurl_path]" id="newurl_path" size="50" value="<?php echo $newurl_path?>" /></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_newurl_path')?></th>
 <td class="y-bg"><input type="text" class="input-text" name="setconfig[newurl_path]" id="newurl_path" size="50" value="<?php echo $newurl_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_upload_url'] = '附件URL访问路径';
$LANG['setting_newurl_path'] = '新增的URL地址';
$LANG['setting_upload_url'] = '附件URL访问路径';
$LANG['setting_newurl_path'] = '新增的URL地址';

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

文件路径:/phpcms/languages/zh-cn/admin.lang.php ,在第42行左右,在’img_path’后面添加’newurl_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','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','newurl_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','newurl_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 中添加自定义全局变量教程结束,自定义变量优势方便维护,Enjoy~

原文链接:https://blog.qiaohewei.cc/2022/02/13/phpcmsv9_add_global_variable/

1639043627-11614406329-update_info.jpg

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK