webman controller文件夹下支持不支持再建文件夹

admin007

截图

2486 8 0
8个回答

six
  • 暂无评论
不败少龙

哪里不支持了 你的namespace引用是不是有问题

  • admin007 2021-04-09

    嗯,访问的时候怎么访问,是域名地址/v1/user/方法名 还是 域名地址/user/方法名

  • 不败少龙 2021-04-09

    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']);
    });

    });

  • 不败少龙 2021-04-09

    这样试试能不能行

不败少龙

截图
截图
截图

葱香小油条

目前确实不支持多级子目录默认访问,必须设置相应路由

  • 暂无评论
admin007

参考你的发的做的,提示:截图

admin007

截图
截图

JustForFun

截图

你可以换种写法。在 app 下直接建 v1、v2 等子目录,再将 controller 等放进子目录中。
这只是一个可用 demo,不确定你后面会不会遇到其它坑。

wenmingpig

前天也遇到此问题,自动路由没那么多层级,手动写路由或改下内核吧。
vendor\workerman\webman-framework\src\App.php 大约452行,添加类似如下代码,试用了好像都正常。


        // 再多级 2021-04-18 10:04 Wolix
        if(count($explode) > 3){
            $action = End($explode); // 最后这个为action
            array_pop($explode); // 去掉最后的那个action
            array_shift($explode); //去掉第一个

            $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,
                ];
            }
        }
        // 再多级 2021-04-18 10:04 Wolix end

        return false;
  • 暂无评论
年代过于久远,无法发表回答
🔝