哪里不支持了 你的namespace引用是不是有問(wèn)題
Route::group('/api', function () {
Route::group('/v1', function () {
Route::any('/index/index', [\app\api\controller\v1\Index::class,'index']);
});
Route::group('/v2', function () {
Route::any('/index/index', [\app\api\controller\v2\Index::class,'index']);
});
});
你可以換種寫(xiě)法。在 app 下直接建 v1、v2 等子目錄,再將 controller 等放進(jìn)子目錄中。
這只是一個(gè)可用 demo,不確定你后面會(huì)不會(huì)遇到其它坑。
前天也遇到此問(wèn)題,自動(dòng)路由沒(méi)那么多層級(jí),手動(dòng)寫(xiě)路由或改下內(nèi)核吧。
vendor\workerman\webman-framework\src\App.php 大約452行,添加類(lèi)似如下代碼,試用了好像都正常。
// 再多級(jí) 2021-04-18 10:04 Wolix
if(count($explode) > 3){
$action = End($explode); // 最后這個(gè)為action
array_pop($explode); // 去掉最后的那個(gè)action
array_shift($explode); //去掉第一個(gè)
$controller = \implode("\\", $explode);
$controller_class = "app\\$app\\controller\\$controller";
if (static::loadController($controller_class) && \is_callable([$instance = static::$_container->get($controller_class), $action])) {
return [
'app' => $app,
'controller' => \get_class($instance),
'action' => static::getRealMethod($controller_class, $action),
'instance' => $instance,
];
}
}
// 再多級(jí) 2021-04-18 10:04 Wolix end
return false;