Skip to content

Commit e710186

Browse files
committed
Merge pull request symfony#3452 from xabbuh/issue-3450
clarify that optional placeholders can only be used at the end of a rout...
2 parents d3ee46b + 678d113 commit e710186

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

book/routing.rst

+7
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,13 @@ match, giving the ``page`` parameter a value of ``2``. Perfect.
432432
| /blog/2 | blog | {page} = 2 |
433433
+--------------------+-------+-----------------------+
434434

435+
.. caution::
436+
437+
Of course, you can have more than one optional placeholder (e.g. ``/blog/{slug}/{page}``),
438+
but everything after an optional placeholder must be optional. For example,
439+
``/{page}/blog`` is a valid path, but ``page`` will always be required
440+
(i.e. simply ``/blog`` will not match this route).
441+
435442
.. tip::
436443

437444
Routes with optional parameters at the end will not match on requests

book/translation.rst

+10-8
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ by the routing system using the special ``_locale`` parameter:
453453
454454
contact:
455455
path: /{_locale}/contact
456-
defaults: { _controller: AcmeDemoBundle:Contact:index, _locale: en }
456+
defaults: { _controller: AcmeDemoBundle:Contact:index }
457457
requirements:
458458
_locale: en|fr|de
459459
@@ -467,7 +467,6 @@ by the routing system using the special ``_locale`` parameter:
467467
468468
<route id="contact" path="/{_locale}/contact">
469469
<default key="_controller">AcmeDemoBundle:Contact:index</default>
470-
<default key="_locale">en</default>
471470
<requirement key="_locale">en|fr|de</requirement>
472471
</route>
473472
</routes>
@@ -478,12 +477,15 @@ by the routing system using the special ``_locale`` parameter:
478477
use Symfony\Component\Routing\Route;
479478
480479
$collection = new RouteCollection();
481-
$collection->add('contact', new Route('/{_locale}/contact', array(
482-
'_controller' => 'AcmeDemoBundle:Contact:index',
483-
'_locale' => 'en',
484-
), array(
485-
'_locale' => 'en|fr|de',
486-
)));
480+
$collection->add('contact', new Route(
481+
'/{_locale}/contact',
482+
array(
483+
'_controller' => 'AcmeDemoBundle:Contact:index',
484+
),
485+
array(
486+
'_locale' => 'en|fr|de',
487+
)
488+
));
487489
488490
return $collection;
489491

0 commit comments

Comments
 (0)