1

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

Dinesh s
  • 313
  • 4
  • 19

1 Answers1

1

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

odan
  • 4,757
  • 5
  • 20
  • 49
  • Thanks Odan i will try with query sting – Dinesh s Mar 03 '22 at 09:55
  • Odan in fast route the only way to accept the url encode character is by query string right – Dinesh s Mar 03 '22 at 13:43
  • @Dineshkarthik I don't understand your question. FastRoute is a library used by Slim under the hood. When you use a QueryString (`?param1=value1`) then FastRoute should not be affected. – odan Mar 03 '22 at 15:16
  • if fast route we cannot able use `%2f` in url right if we need to use the we need query string – Dinesh s Mar 03 '22 at 15:27
  • Yes, for complexer queries, better use a HTTP QueryString. – odan Mar 03 '22 at 18:01