File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,28 @@ a certain route::
229229 of the current :class: `Symfony\\ Component\\ Routing\\ RequestContext ` does
230230 not match the requirement.
231231
232+ Check if a Route Exists
233+ ~~~~~~~~~~~~~~~~~~~~~~~
234+
235+ In highly dynamic applications, it may be necessary to check whether a route
236+ exists before using it to generate a URL. In those cases, don't use the
237+ :method: `Symfony\\ Component\\ Routing\\ Router::getRouteCollection ` method because
238+ that regenerates the routing cache and slows down the application.
239+
240+ Instead, try to generate the URL and catch the
241+ :class: `Symfony\\ Component\\ Routing\\ Exception\\ RouteNotFoundException ` thrown
242+ when the route doesn't exist::
243+
244+ use Symfony\Component\Routing\Exception\RouteNotFoundException;
245+
246+ // ...
247+
248+ try {
249+ $url = $generator->generate($dynamicRouteName, $parameters);
250+ } catch (RouteNotFoundException $e) {
251+ // the route is not defined...
252+ }
253+
232254Load Routes from a File
233255~~~~~~~~~~~~~~~~~~~~~~~
234256
You can’t perform that action at this time.
0 commit comments