Slim v4 URL 解码返回 404
我正在将我的应用程序从 slim v2 升级到 v4
我有一个路由函数,
$group->get('/get-data/{url}', '\V2:get_data');
当我传递 url 变量时,
api.app.com/get-data/xxxx%2fyyyyy
路由给出 404 ,
我尝试使用 args 访问函数中的 url,但是
function get_data($request,$response,$args){
$slug =$args['url'];
print_r($slug);die;
}
但它甚至没有输入 到函数中
任何人都可以帮助我们如何在 slim v4 中使用 %2f
传递动态参数
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Slim 使用 fastroute 作为路由器。这只是 FastRoute 的已知限制。
原因是,
%2f
在内部转换为/
,这也是一个路径段分隔符。您可能还会注意到%2e
也有类似的行为,它只是一个.
点。但不要问我为什么点会发生这种情况。URL 路径参数应该更“简单”,例如只是一个数值或只是简单的字符串。这就是为什么许多人只使用 62 个字母数字字符(即 A–Z、a–z、0–9)。 *
对于更复杂的查询,典型的 查询字符串可能更合适。这不会影响路由路径。
如果您想使用 Symfony 路由器,请查看此示例存储库:
https://github.com/l0gicgate/slim4-symfony-router-exp
Slim uses fastroute as router. This is just a known limitation with FastRoute.
The reason is,
%2f
is internally converted to/
, and this is also a path segment delimiter. You may also notice a similar behavior with%2e
which is just a.
dot. But don't ask me why this happens with the dot.URL path parameters should be more "simple", for example just a numeric value or just simple strings. That’s why many use just the 62 alphanumeric characters (i.e. A–Z, a–z, 0–9). *
For more complex queries, a typical query string might be more appropriate. This would then not affect the routing path.
If you want to use the Symfony router, check out this sample repo:
https://github.com/l0gicgate/slim4-symfony-router-exp