diff --git a/components/routing.rst b/components/routing.rst
index a46922505ea..9c9c454cd3b 100644
--- a/components/routing.rst
+++ b/components/routing.rst
@@ -399,7 +399,7 @@ routes with UTF-8 characters:
class DefaultController extends AbstractController
{
/**
- * @Route("/category/{name}", name="route1", options={"utf8": true})
+ * @Route("/category/{name}", name="route1", utf8=true)
*/
public function category()
{
@@ -411,8 +411,7 @@ routes with UTF-8 characters:
route1:
path: /category/{name}
controller: App\Controller\DefaultController::category
- options:
- utf8: true
+ utf8: true
.. code-block:: xml
@@ -422,9 +421,10 @@ routes with UTF-8 characters:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
-
-
-
+
.. code-block:: php
@@ -437,12 +437,61 @@ routes with UTF-8 characters:
return function (RoutingConfigurator $routes) {
$routes->add('route1', '/category/{name}')
->controller([DefaultController::class, 'category'])
- ->options([
- 'utf8' => true,
- ])
+ ->utf8()
;
};
+.. versionadded:: 4.3
+
+ The ``utf8`` shortcut has been introduced in Symfony 4.3.
+ Before you has to use the ``options`` setting to define
+ this value:
+
+ .. configuration-block::
+
+ .. code-block:: php-annotations
+
+ route1:
+ path: /category/{name}
+ controller: App\Controller\DefaultController::category
+ options: { utf8: true }
+
+ .. code-block:: yaml
+
+ route1:
+ path: /category/{name}
+ controller: App\Controller\DefaultController::category
+ utf8: true
+
+ .. code-block:: xml
+
+
+
+
+
+
+
+
+
+ .. code-block:: php
+
+ // config/routes.php
+ namespace Symfony\Component\Routing\Loader\Configurator;
+
+ use App\Controller\DefaultController;
+
+ return function (RoutingConfigurator $routes) {
+ $routes->add('route1', '/category/{name}')
+ ->controller([DefaultController::class, 'category'])
+ ->options(['utf8' => true])
+ ;
+ };
+
In this route, the ``utf8`` option set to ``true`` makes Symfony consider the
``.`` requirement to match any UTF-8 characters instead of just a single
byte character. This means that so the following URLs would match:
@@ -467,7 +516,7 @@ You can also include UTF-8 strings as routing requirements:
* "/category/{name}",
* name="route2",
* defaults={"name"="한국어"},
- * options={"utf8": true}
+ * utf8=true
* )
*/
public function category()
@@ -482,8 +531,7 @@ You can also include UTF-8 strings as routing requirements:
controller: 'App\Controller\DefaultController::category'
defaults:
name: "한국어"
- options:
- utf8: true
+ utf8: true
.. code-block:: xml
@@ -493,9 +541,11 @@ You can also include UTF-8 strings as routing requirements:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
-
+
한국어
-
@@ -512,9 +562,7 @@ You can also include UTF-8 strings as routing requirements:
->defaults([
'name' => '한국어',
])
- ->options([
- 'utf8' => true,
- ])
+ ->utf8()
;
};
diff --git a/routing.rst b/routing.rst
index 10e708d829e..357fc5f36a6 100644
--- a/routing.rst
+++ b/routing.rst
@@ -623,7 +623,10 @@ With all of this in mind, check out this advanced example:
/**
* @Route(
* "/articles/{_locale}/{year}/{slug}.{_format}",
- * defaults={"_format": "html"},
+ * defaults={
+ * "_locale": "en",
+ * "_format": "html"
+ * },
* requirements={
* "_locale": "en|fr",
* "_format": "html|rss",
@@ -643,6 +646,7 @@ With all of this in mind, check out this advanced example:
path: /articles/{_locale}/{year}/{slug}.{_format}
controller: App\Controller\ArticleController::show
defaults:
+ _locale: en
_format: html
requirements:
_locale: en|fr
@@ -662,6 +666,7 @@ With all of this in mind, check out this advanced example:
path="/articles/{_locale}/{year}/{slug}.{_format}"
controller="App\Controller\ArticleController::show">
+ en
html
en|fr
html|rss
@@ -681,6 +686,7 @@ With all of this in mind, check out this advanced example:
$routes->add('article_show', '/articles/{_locale}/{year}/{slug}.{_format}')
->controller([ArticleController::class, 'show'])
->defaults([
+ '_locale' => 'en',
'_format' => 'html',
])
->requirements([
@@ -739,6 +745,91 @@ that are special: each adds a unique piece of functionality inside your applicat
``_locale``
Used to set the locale on the request (:ref:`read more `).
+You can also use special attributes to configure them (except ``_fragment``):
+
+.. configuration-block::
+
+ .. code-block:: php-annotations
+
+ // src/Controller/ArticleController.php
+
+ // ...
+ class ArticleController extends AbstractController
+ {
+ /**
+ * @Route(
+ * "/articles/{_locale}/search.{_format}",
+ * locale="en",
+ * format="html",
+ * requirements={
+ * "_locale": "en|fr",
+ * "_format": "html|xml",
+ * }
+ * )
+ */
+ public function search()
+ {
+ }
+ }
+
+ .. code-block:: yaml
+
+ # config/routes.yaml
+ article_search:
+ path: /articles/{_locale}/search.{_format}
+ controller: App\Controller\ArticleController::search
+ locale: en
+ format: html
+ requirements:
+ _locale: en|fr
+ _format: html|xml
+
+ .. code-block:: xml
+
+
+
+
+
+
+
+ en|fr
+ html|rss
+
+
+
+
+ .. code-block:: php
+
+ // config/routes.php
+ namespace Symfony\Component\Routing\Loader\Configurator;
+
+ use App\Controller\ArticleController;
+
+ return function (RoutingConfigurator $routes) {
+ $routes->add('article_show', '/articles/{_locale}/search.{_format}')
+ ->controller([ArticleController::class, 'search'])
+ ->locale('en')
+ ->format('html)
+ ->requirements([
+ '_locale' => 'en|fr',
+ '_format' => 'html|rss',
+ ])
+ ;
+ };
+
+Those attributes can also be used for imports.
+
+.. versionadded::
+
+ The special attributes has been introduced in Symfony 4.3.
+
.. _routing-trailing-slash-redirection:
Redirecting URLs with Trailing Slashes