top-think / think-swoole

Swoole extend for thinkphp
Apache License 2.0
457 stars 105 forks source link

请教下tp8多应用模式下 think-swoole php think swoole 子应用下 路由无效怎么解决 #364

Open pasawu opened 7 months ago

pasawu commented 7 months ago

请教下tp8多应用模式下 think-swoole php think swoole 子应用下 路由无效怎么解决

app/ ├── api/ │ ├── route/ │ │ ├── api.php │ │ └── user.php │ └── ... ├── adminapi/ │ ├── route/ │ │ ├── api.php │ │ └── user.php │ └── ... └── route/ └── app.php

只有route下的路由有效api和adminapi下的route无效

1207702931 commented 7 months ago

Event::listen(RouteLoaded::class, function () { $url = app()->request->url(); $url = str_starts_with($url, '/') ? substr($url, 1) : $url; $sub_app = substr($url, 0, strpos($url, '/')); app()->route->clear(); foreach (glob(root_path() . 'app/'.$sub_app . '/route/*.php') as $item) { include $item; } }); 试试这样

pasawu commented 7 months ago

Event::listen(RouteLoaded::class, function () { $url = app()->request->url(); $url = str_starts_with($url, '/') ? substr($url, 1) : $url; $sub_app = substr($url, 0, strpos($url, '/')); app()->route->clear(); foreach (glob(root_path() . 'app/'.$sub_app . '/route/*.php') as $item) { include $item; } }); 试试这样

请问下是在什么文件加这段代码,谢谢