【121.1】php实现路由分配的方法

<?php
// 权限控制
include_once './auth.php';
// 应用入口文件
date_default_timezone_set("Asia/Shanghai");
header('Content-type: text/html;charset=utf-8');
// 项目根路径
define('BASEPATH', dirname(__FILE__));
// 调试模式
define('APP_DEBUG', True);
// 引入配置文件
include_once BASEPATH . '/config/config.php';
// 路由控制
$router = include_once BASEPATH . '/config/router.php';
if ($_SERVER['HTTP_HOST'] !== 'xxx.com') {
    var_dump('当前host不被允许');
} else {
    $request_path = str_replace('/index.php', '', $_SERVER['PHP_SELF']);
    $request_query = getCurrentQuery();
    if (array_key_exists($request_path, $router)) {
        $module_file = BASEPATH . $router[$request_path]['file_name'];
        $class_name = $router[$request_path]['class_name'];
        $method_name = $router[$request_path]['method_name'];
        if (file_exists($module_file)) {
            include $module_file;
            $obj_module = new $class_name();
            if (!method_exists($obj_module, $method_name)) {
                die("要调用的方法不存在");
            } else {
                if (is_callable(array($obj_module, $method_name))) {
                    $obj_module->$method_name($request_query, $_POST);
                }
            }
        } else {
            die("定义的模块不存在");
        }
    } else {
        echo '页面不存在';
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值