Moeezalikhan
Moeezalikhan

Reputation: 41

set dynamic routing in Symfony2

I want these two dynamic routes to pass from the single controller https://www.example.com/Andersonville_apartments.html https://www.example.com/Albany_Park_apartments.html

and the route in controller which i have called is this

@Route("/{id}_apartments.html", name="neighborhood_detail")

Now the problem is this that it detect the First URL with single underscore but doesn't detect the second one with two Underscore as controller doesnot detect the route . Can Any one help me to do this PS: I cannot remove the underscore and replace it with the / as its the requirement .

Upvotes: 1

Views: 57

Answers (1)

kurtec
kurtec

Reputation: 128

You should add requirements parameter to your route definition to allow underscores. Something like this :

@Route("/{id}_apartments.html", name="neighborhood_detail"), requirements={"id"="[a-zA-Z0-9_]+"})

Hope this help you

Upvotes: 1

Related Questions