针对hyperf框架改造----路由(routes)多文件多目录多前缀支持
Laravel框架
530
0
0
2022-08-17
目的


第一步 新增助手函数
- 添加助手函数的方法就不在这里赘述,不清楚的可以百度一下
| 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); |
| } |
| } |
| } |
| } |
| } |
| } |
第三步 加载路由
- 在config目录下的
routes.php
中写入函数:
| <?php |
| declare(strict_types=1); |
| reloadRoute(); |
第三步 添加routers目录
- 在项目根(/)目录新增
routes
,达到效果例如:
| routes |
| ├── admin |
| │ ├── user.php |
| ├── front |
| │ ├── home.php |
| │ ├── user.php |