-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Document to NEVER use getRouteCollection() / how to check if route exists #6710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@wouterj Symfony provides (In any case, an application which is not sure about its own routes and needs to check if they exist, looks fragile to me). |
It's less fragile than you might think. Take for example a site using the CMF Routing bundle, which loads routes from a database. An admin might create/remove routes that an app depends on. For example, in the CMF we had to manage the case of a menu item trying to link to a route that was removed.
The router is dumped in cache. This removes the complete The cached generator has a hash map of route name -> route tokens mappings. We might be able to reuse that hash map in the router, but not sure if it's worth it. |
@wouterj: But providing a new |
Maybe we should even consider to set this method to |
My URL structure is like facebook/twitter: To let the user set the username, I need to check if a path of a route matches a username. A hasRoute() method like the one in the referenced issue wouldn't help because it only checks by route name and not path. Update, found the answer: |
Fixed by #9845. |
It isn't clear for people to not use
Router#getRouteCollection()
. Using this method will regenerate the Routing cache on each request, making apps very slow. I think we should explicitely tell people to not use this method.A common use case of this method seems to be checking whether a route exists (symfony/symfony#19270, http://stackoverflow.com/q/14136484/1149495, http://stackoverflow.com/q/17241235/1149495, etc.). Maybe we can document to catch the
RouteNotFoundException
in such cases and then explain to not usegetRouteCollection()
.The text was updated successfully, but these errors were encountered: