Slim v4 URL 解码返回 404

发布于 2025-01-11 11:08:25 字数 471 浏览 2 评论 0 原文

我正在将我的应用程序从 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 传递动态参数

i am upgrading my application from slim v2 to v4

i have one route function menitoned below

$group->get('/get-data/{url}', '\V2:get_data'); 

when i pass the url variable a

api.app.com/get-data/xxxx%2fyyyyy

the route gives 404 ,

i tried with accessing the url in function with args but

function get_data($request,$response,$args){

  $slug =$args['url'];
  print_r($slug);die;

}

but it doesn’t even entering into the function

can anyone help with how we can pass the dynamic para with %2f in slim v4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不忘初心 2025-01-18 11:08:25

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文