How do I enforce a requirement that a paramater in a route be a string?
Given the route
my_foobar_route: url: /example/routing/:s1/:id requirements: { id: \d+ }
Can anyone remind me of how to force param s1 to be a string?
If you don't care what the string contains or if you don't know beforehand what it will contain, try the following:
my_foobar_route:
url: /example/routing/:s1/:id
requirements:
id: \d+
s1: "[^/]+"
This will allow all characters except the '/' character which is used as a separator for the parameters. With the expression
my_foobar_route:
url: /example/routing/:s1/:id
requirements:
id: \d+
s1: "[^/]{3,}"
you could force the string to be at least three characters long.
Don't forget to put Regexes with square brackets in quotes! If you forget them, the YAML parser for the routes will interpret them as an array expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With