phpcms在后台新增联系电话和地址

文章描述:

phpcms内容管理系统没有联系方式和联系地址字段,那么phpcms怎么在后台设置-基本设置里面新增自定义字段呢?

1、打开phpcms\modules\admin\functions\global.func.php文件,找到以下方法:

function set_config($config, $filename="system") {
   $configfile = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.$filename.'.php';
   if(!is_writable($configfile)) showmessage('Please chmod '.$configfile.' to 0777 !');
   $pattern = $replacement = array();
   foreach($config as $k=>$v) {
      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'))) {
         $v = trim($v);
         $configs[$k] = $v;
         $pattern[$k] = "/'".$k."'\s*=>\s*([']?)[^']*([']?)(\s*),/is";
           $replacement[$k] = "'".$k."' => \${1}".$v."\${2}\${3},";
      }
   }
   $str = file_get_contents($configfile);
   $str = preg_replace($pattern, $replacement, $str);
   return pc_base::load_config('system','lock_ex') ? file_put_contents($configfile, $str, LOCK_EX) : file_put_contents($configfile, $str);
}

替换为以下代码:

function set_config($config, $filename="system") {
   $configfile = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.$filename.'.php';
   if(!is_writable($configfile)) showmessage('Please chmod '.$configfile.' to 0777 !');
   $pattern = $replacement = array();
   foreach($config as $k=>$v) {
      if(in_array($k,array('web_mobile','web_address','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'))) {
         $v = trim($v);
         $configs[$k] = $v;
         $pattern[$k] = "/'".$k."‘\s*=>\s*([‘]?)[^’]*([‘]?)(\s*),/is";$replacement[$k] = "‘".$k."‘ => \${1}".$v."\${2}\${3},";}}
         $str = file_get_contents($configfile);
         $str = preg_replace($pattern, $replacement, $str);
         return pc_base::load_config('system','lock_ex') ? file_put_contents($configfile, $str, LOCK_EX) : file_put_contents($configfile, $str);
}

在这个方法里面我们新增了web_mobile和web_address两个字段

2、打开phpcms\base.php文件,找到下面代码:

//定义网站根路径
define('WEB_PATH',pc_base::load_config('system','web_path'));
//js 路径
define('JS_PATH',pc_base::load_config('system','js_path'));
//css 路径
define('CSS_PATH',pc_base::load_config('system','css_path'));
//img 路径
define('IMG_PATH',pc_base::load_config('system','img_path'));
//动态程序路径
define('APP_PATH',pc_base::load_config('system','app_path'));

在后面添加以下代码:

define('WEB_MOBILE',pc_base::load_config('system','web_mobile'));
define('WEB_ADDRESS',pc_base::load_config('system','web_address'));

3、打开/phpcms/modules/admin/templates/setting.tpl.php文件,找到以下代码:

<tr>
  <th width="120"><?php echo L('setting_admin_email')?></th>
  <td class="y-bg"><input type="text" class="input-text" name="setting[admin_email]" id="admin_email" size="30" value="<?php echo $admin_email?>"/></td>
</tr>

在上面添加以下代码:

<tr>
    <th width="120"><?php echo L('setting_web_mobile')?></th>
    <td class="y-bg"><input type="text" class="input-text" name="setting[web_mobile]" id="web_mobile" size="30" value="<?php echo $web_mobile;?>"/></td>
</tr>
<tr>
    <th width="120"><?php echo L('setting_web_address')?></th>
    <td class="y-bg"><input type="text" class="input-text" name="setting[web_address]" id="web_address" size="30" value="<?php echo $web_address;?>"/></td>
</tr>

4、打开/phpcms/languages/zh-cn/admin.lang.php文件,找到以下代码:

$LANG['setting_admin_email'] = '管理员邮箱';

在上面添加以下代码:

$LANG['setting_web_mobile'] = '联系电话';
$LANG['setting_web_address'] = '联系地址';

5、打开/phpcms/modules/admin/setting.php文件,找到以下代码:

$setting['admin_email'] = is_email($_POST['setting']['admin_email']) ? trim($_POST['setting']['admin_email']) : showmessage(L('email_illegal'),HTTP_REFERER);

在上面添加以下代码:

$setting['web_mobile'] = trim($_POST['setting']['web_mobile']);
$setting['web_address'] = trim($_POST['setting']['web_address']);

完成以上步骤后在后台刷新即可,就可以看见我们新增的自定义字段了,新增字段储存在v9_module数据表setting字段里面,如果还需要添加其它字段,可以根据自己需求添加。

6、打开phpcms/modules/content/index.php文件,在init里面添加以下代码:

$this->db = pc_base::load_model('module_model');
$info = $this->db->get_one(array('module'=>'admin')); 
$pub = string2array($info['setting']);

上面是查询module表admin字段

7、在模板调用代码如下:

<?php echo $pub['web_mobile'];?>

 

发布时间:2021/08/06

发表评论