三多运维

某鸟门户系统二次开发模版引用最佳实践

2026/05/14
4
0

基于某鸟门户系统-项目源码路由机制分析

根据项目的 index.php 代码,系统会按以下步骤处理请求:

关键路由逻辑(第454-590行)

//路由分配
$requestPathArr_ = explode('/', $reqUri);
$template_ = explode("?", $requestPathArr_[1]);
$template = str_replace('.html', '', $template_[0]);

// 判断是否是单页模板(如 /article/list.html)
if((strstr($reqUri, 'http') || count($requestPathArr_) < 3) && 
strstr($requestPathArr_[1], '.html') && ($cityDomainType == 
0 || $isSystemPage)){
    $template = checkPagePath($service, $template, $reqUri);
}

基于官方Article模块的工作原理

当访问 https://{域名}/article/service.html 时:

  1. requestPathArr_[1] = article (模块名)
  2. requestPathArr_[2] = service.html (模板名)
  3. 系统会在 templates/article/ 目录下查找 service.html

解决方案:创建service模块

步骤1:创建模块目录结构

cd /****/net

# 创建电脑模板目录
mkdir -p templates/service/skin1

# 创建移动端模板目录(如果需要)
mkdir -p templates/service/touch/default

步骤3:复制落地页文件到模板目录

# 将自己所有落地页复制到模板目录
cp /{自建模版}/service/*.html /****/net/templates/service/skin1/

# 如果需要移动端版本
cp /{自建模版}/service/*.html /****/net/templates/service/touch/default/

步骤2:创建模块配置文件

在 include/config/ 目录下创建 service.inc.php :

<?php
// service模块配置文件
$serviceConfig = array(
    "name" => "service",
    "title" => "服务落地页",
    "description" => "服务落地页模块",
    "template" => "skin1",           // PC端模板目录
    "touchTemplate" => "default",       // 移动端模板目录(关键!)
    "allowRegister" => 0,
    "needLogin" => 0,
    "map" => 0,
    "map_key" => "",
    "map_server_key" => "",
    "map_apiFile" => "",
    "channelDomain" => "",
    "subDomain" => 0,
    "visitState" => 0,
    "visitMessage" => "",
);
?>

步骤3:创建模块控制器文件

创建 /www/haido/net/api/handlers/service.controller.php :

<?php
/**
 * Service Module Controller
 * 服务落地页模块控制器
 */

function service($atts = array(), $content = "") {
    global $huoniaoTag;
    
    // 获取模块配置
    $moduleConfig = getModuleConfig('service');
    
    // 输出模块数据到模板
    if(is_array($moduleConfig)){
        foreach($moduleConfig as $key => $value){
            $huoniaoTag->assign('service_'.$key, $value);
        }
    }
    
    return "";
}
?>

确保目录结构正确:

/{站点根目录}/
├── api/
│   └── handlers/
│       └── service.controller.php  # 新增控制器文件
├── include/
│   └── config/
│       └── service.inc.php         # 模块配置文件
└── templates/
    └── service/
        ├── skin1/
        │   ├── brand.html          # 落地页文件
        │   ├── tax.html
        │   └── config.xml          # 模板配置
        └── touch/
            └── default/
                └── brand.html      # 移动端落地页

步骤4:创建配置文件

在 templates/service/skin1/ 目录下创建 config.xml :

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <Data>
        <name>服务落地页</name>
        <version>1.0</version>
        <router>0</router>
        <author>Haido</author>
    </Data>
</root>

步骤5:在数据库中注册模块

登录数据库执行以下SQL:

简版示例SQL

INSERT INTO `#@__site_module` (`name`, `subject`, `type`, 
`state`, `sort`, `addtime`) 
VALUES ('service', '服务落地页', 0, 0, 99, UNIX_TIMESTAMP());

数据库导出SQL

INSERT INTO `hn_site_module` (`id`, `type`, `parentid`, `title`, `name`, `icon`, `note`, `state`, `weight`, `subnav`, `filelist`, `domainRules`, `catalogRules`, `installsql`, `insertsql`, `delsql`, `version`, `date`, `wx`, `bold`, `target`, `color`, `link`, `subject`, `app`, `bd`, `qm`, `dy`, `pc`, `h5`, `harmony`, `ios`, `android`, `configFile`) VALUES (NULL, '0', '1', '服务', 'service', '0', '6', '', '', NULL, NULL, NULL, NULL, '', 'v1.0.0', '1730517922', '1', '0', '0', '', '', '服务', '0', '0', '0', '0', '1', '1', '1', '1', '1', NULL)

步骤6:验证配置

修改完成后,清除缓存:

rm -rf /{自建站点}/cache/*

访问方式

完成以上检查,再次 https://{域名}/service/brand.html 可正常访问!