Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3DMXM opened this issue Jan 19, 2023 · 9 comments
Open

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

3DMXM opened this issue Jan 19, 2023 · 9 comments

Comments

@3DMXM
Copy link

3DMXM commented Jan 19, 2023

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

// 用户个人中心
'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
Copy link
Collaborator

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

@3DMXM
Copy link
Author

3DMXM commented Jan 19, 2023

您好,是把'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
Copy link
Collaborator

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

@3DMXM
Copy link
Author

3DMXM commented Jan 20, 2023

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

@billge1205
Copy link
Collaborator

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

@3DMXM
Copy link
Author

3DMXM commented Jan 20, 2023

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

@billge1205
Copy link
Collaborator

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

@billge1205
Copy link
Collaborator

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

@3DMXM
Copy link
Author

3DMXM commented Jan 30, 2023

好的,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants