Tencent / Biny

Biny is a tiny, high-performance PHP framework for web applications
BSD 3-Clause "New" or "Revised" License
1.69k stars 258 forks source link

反馈一个路由配置相关的Bug #140

Open 3DMXM opened 1 year ago

3DMXM commented 1 year ago

比如说, 我先定义了这样的路由①:

// 用户个人中心
'u/<id:\d+>' => 'space/index',
'u' => 'space/index',

然后有另外一个路由②:

'<path:\w+>' => 'mod/game',

这两个路由都是在 config\config.php文件里面的 routeRule数组里面配置的

然后,如果我访问的是 "http://localhost/taiwu", 正常我是希望他走路由②,但实际上他会这样一个错误:

Fatal error:  Autoload file[taiwspaceAction] is fails in /home/wwwroot/mod/lib/Autoload.php:124
Stack trace:
#0 [internal function]: biny\lib\Autoload::load('taiwspaceAction')
#1 /home/wwwroot/mod/lib/business/Factory.php(68): spl_autoload_call('taiwspaceAction')
#2 /home/wwwroot/mod/lib/business/Factory.php(45): biny\lib\Factory::loadClass('taiwspaceAction', 'taiwspaceAction')
#3 /home/wwwroot/mod/lib/business/Request.php(255): biny\lib\Factory::create('taiwspaceAction')
#4 /home/wwwroot/mod/lib/business/Controller.php(54): biny\lib\Request->getModule(true)
#5 /home/wwwroot/mod/lib/business/Controller.php(42): biny\lib\Controller->call(Object(biny\lib\Request))
#6 /home/wwwroot/mod/lib/business/Controller.php(105): biny\lib\Controller->execute()
#7 /home/wwwroot/mod/lib/App.php(176): biny\lib\Controller->dispatcher()
#8 /home/wwwroot/mod/web/index.php(21): App::run()
#9 {main}

他把taiwu后面的u替换成了space,然后再去找 taiwspaceAction ,发现没找到,结果返回404.

billge1205 commented 1 year ago

看看 全路径路由是否可以设置成 '/u' => '/space/index' 如果不行的话 我得晚点看看

3DMXM commented 1 year ago

您好,是把'u' => 'space/index',改成 '/u' => '/space/index',吗,貌似不行, 新的报错:

Fatal error:  Autoload file[taiwAction] is fails in /home/wwwroot/mod/lib/Autoload.php:124
Stack trace:
#0 [internal function]: biny\lib\Autoload::load('taiwAction')
#1 /home/wwwroot/mod/lib/business/Factory.php(68): spl_autoload_call('taiwAction')
#2 /home/wwwroot/mod/lib/business/Factory.php(45): biny\lib\Factory::loadClass('taiwAction', 'taiwAction')
#3 /home/wwwroot/mod/lib/business/Request.php(255): biny\lib\Factory::create('taiwAction')
#4 /home/wwwroot/mod/lib/business/Controller.php(54): biny\lib\Request->getModule(true)
#5 /home/wwwroot/mod/lib/business/Controller.php(42): biny\lib\Controller->call(Object(biny\lib\Request))
#6 /home/wwwroot/mod/lib/business/Controller.php(105): biny\lib\Controller->execute()
#7 /home/wwwroot/mod/lib/App.php(176): biny\lib\Controller->dispatcher()
#8 /home/wwwroot/mod/web/index.php(21): App::run()
#9 {main}
billge1205 commented 1 year ago

看了下 前缀匹配可以用 '^u' => 'space/index' 年后可以来试一下哈

3DMXM commented 1 year ago

但这样的话,路由① 的 http://localhost/u 就废了。。。

billge1205 commented 1 year ago

不是哈 你反馈的bug主要是因为路由没有按全路径匹配 导致的末尾是u的会被先替换成了 space/index 加了 ^之后 就只会对 http://localhost/u 转成路由 space/index 不再影响 /taiwu 这样的路由了哈

3DMXM commented 1 year ago

理论上用 ^u 就可以只匹配 /u ,但是呢,好像访问 http://localhost/u 会判断路由①没有匹配到,然后去匹配路由②

billge1205 commented 1 year ago

好的 应该是有bug 我晚点修复下

billge1205 commented 1 year ago

更新了下 lib/business/Router.php 默认全匹配了 你可以再用最开始的写法试试 写在前面的优先级更高

3DMXM commented 1 year ago

好的,感谢