File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,28 @@ a certain route::
229
229
of the current :class: `Symfony\\ Component\\ Routing\\ RequestContext ` does
230
230
not match the requirement.
231
231
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
+
232
254
Load Routes from a File
233
255
~~~~~~~~~~~~~~~~~~~~~~~
234
256
You can’t perform that action at this time.
0 commit comments