@@ -256,13 +256,13 @@ expressions - see :doc:`/routing/requirements`.
256
256
Giving {placeholders} a Default Value
257
257
-------------------------------------
258
258
259
- In the previous example, the ``blog_list `` has a path of ``/blog/{page} ``. If the
260
- user goes to ``/blog/1 ``, it will match. But if the user goes to ``/blog ``, it will
261
- **not ** match. As soon as you add a ``{placeholder} `` to a route, it * must * have
262
- a value.
259
+ In the previous example, the ``blog_list `` has a path of ``/blog/{page} ``. If
260
+ the user visits ``/blog/1 ``, it will match. But if they visit ``/blog ``, it
261
+ will **not ** match. As soon as you add a ``{placeholder} `` to a route, it
262
+ * must * have a value.
263
263
264
- So how can we make ``/ blog_list `` once again match when the user goes to `` /blog ``?
265
- By adding a *default * value:
264
+ So how can you make ``blog_list `` once again match when the user visits
265
+ `` /blog ``? By adding a *default * value:
266
266
267
267
.. configuration-block ::
268
268
@@ -309,6 +309,7 @@ By adding a *default* value:
309
309
<route id =" blog_list" path =" /blog/{page}" >
310
310
<default key =" _controller" >AppBundle:Blog:list</default >
311
311
<default key =" page" >1</default >
312
+
312
313
<requirement key =" page" >\d+</requirement >
313
314
</route >
314
315
@@ -322,19 +323,23 @@ By adding a *default* value:
322
323
use Symfony\Component\Routing\Route;
323
324
324
325
$collection = new RouteCollection();
325
- $collection->add('blog_list', new Route('/blog/{page}', array(
326
- '_controller' => 'AppBundle:Blog:list',
327
- 'page' => 1,
328
- ), array(
329
- 'page' => '\d+'
330
- )));
326
+ $collection->add('blog_list', new Route(
327
+ '/blog/{page}',
328
+ array(
329
+ '_controller' => 'AppBundle:Blog:list',
330
+ 'page' => 1,
331
+ ),
332
+ array(
333
+ 'page' => '\d+'
334
+ )
335
+ ));
331
336
332
337
// ...
333
338
334
339
return $collection;
335
340
336
- Now, when the user goes to ``/blog ``, the ``blog_list `` route will match and `` $page ``
337
- will default to a value of ``1 ``.
341
+ Now, when the user visits ``/blog ``, the ``blog_list `` route will match and
342
+ `` $page `` will default to a value of ``1 ``.
338
343
339
344
.. index ::
340
345
single: Routing; Advanced example
0 commit comments