@@ -258,8 +258,8 @@ This will make the routing put the document into the request parameters and if
258
258
your controller specifies a parameter called ``$contentDocument ``, it will be
259
259
passed this document.
260
260
261
- You can also use variable patterns for the URL and define requirements and
262
- defaults::
261
+ You can also use variable patterns for the URL and define requirements with
262
+ `` setRequirement `` and defaults with `` setDefault `` ::
263
263
264
264
// do not forget leading slash if you want /projects/{id} and not /projects{id}
265
265
$route->setVariablePattern('/{id}');
@@ -277,19 +277,24 @@ it gets chosen. Otherwise, routing checks if ``/routes/projects`` has a pattern
277
277
that matches. If not, the top document at ``/routes `` is checked for a matching
278
278
pattern.
279
279
280
- Of course you can also have several parameters, as with normal Symfony
281
- routes. The semantics and rules for patterns, defaults and requirements are
282
- exactly the same as in core routes.
280
+ The semantics and rules for patterns, defaults and requirements are exactly the
281
+ same as in core routes. If you have several parameters, or static bits *after *
282
+ a parameter, make them part of the variable pattern::
283
+
284
+ $route->setVariablePattern('/{context}/item/{id}');
285
+ $route->setRequirement('context', '[a-z]+');
286
+ $route->setRequirement('id', '\d+');
283
287
284
288
.. note ::
285
289
286
290
The ``RouteDefaultsValidator `` validates the route defaults parameters.
287
291
For more information, see :ref: `bundle-routing-route-defaults-validator `.
288
292
289
- Your controller can expect the ``$id `` parameter as well as the ``$contentDocument ``
290
- as you set a content on the route. The content could be used to define an intro
291
- section that is the same for each project or other shared data. If you don't
292
- need content, you can just not set it in the route document.
293
+ With the above example, your controller can expect both the ``$id `` parameter
294
+ as well as the ``$contentDocument `` if you set a content on the route and have
295
+ a variable pattern with ``{id} ``. The content could be used to define an intro
296
+ section that is the same for each id. If you don't need content, you can also
297
+ omit setting a content document on the route document.
293
298
294
299
.. _component-route-generator-and-locales :
295
300
0 commit comments