if (! function_exists('reloadRoute')) {
/**
* 加载路由.
*/
function reloadRoute()
{
$path = BASE_PATH . '/routes';
$dirs = scandir($path);
foreach ($dirs as $dir) {
if ($dir != '.' && $dir != '..') {
$routeFilePath = $path . "/{$dir}";
$files = scandir($routeFilePath);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
require_once $routeFilePath . '/' . basename($file);
}
}
}
}
}
}
PHP
Copy
routes.php
中写入在家路由函数:<?php
declare(strict_types=1);
reloadRoute();
PHP
Copy
routes
,达到效果例如:routes
├── admin // 后台路由
│ ├── user.php // 用户接口路由
├── front // 前台
│ ├── home.php // 前台对外公共路由
│ ├── user.php // 用户路由