php 路由分发

<?php
// 路由分发
// 加载所有的依赖
spl_autoload_register(function ($class_name){
    require "./controller/{$class_name}.php";
});

// 从路由中获取参数
$action = $_GET['a'] ?? "a";
$control = $_GET['c'] ?? "c";
$action = strtolower($action);   // 全部转成小写
$control = ucfirst(strtolower($control));  // 先转成小写,然后将首字母转成大写


$action = $action."Action";
$control = $control."Controller";

// 执行对应的类和方法
$obj = new $control();
$obj -> $action();


?>

 

posted @ 2021-08-02 14:53  老鲜肉  阅读(144)  评论(0编辑  收藏  举报