Reputation: 1847
I have a route like:
pattern: /{name}-id{id}/
defaults: { _controller: mycontroller:myfunc }
requirements:
name: "[a-z0-9-]+"
id: "[0-9]+"
which works fine. Now I want to make the route work for multiple pathes, so that it's triggered every time the url ends with -id{id}/, like:
/{name}-id{id}/
/level1/{name}-id{id}/
/level1/level2/{name}-id{id}/
/level1/level2/level3/{name}-id{id}/
and so on. How should this be done without repeating the definition of the route endless times?
Upvotes: 2
Views: 249
Reputation: 64476
By default, the Symfony Routing component requires that the parameters match the following regular expression: [^/]+. This means that all characters are allowed except /.
You must explicitly allow / to be part of your placeholder by specifying a more permissive regular expression for i
You can adjust your route as
pattern: /{path}/{name}-id{id}/
defaults: { _controller: mycontroller:myfunc }
requirements:
path: .+
name: "[a-z0-9-]+"
id: "[0-9]+"
Upvotes: 3