New in Symfony 4.3: Simpler Routing Options Config
Contributed by
Jules Pietri
in #30508.
The Routing component maps HTTP requests to PHP code using some configuration options defined for each of the application routes. In Symfony 4.3 we made some improvements to configure some of those options more easily.
First, we've exposed the Unicode routing support (added back in Symfony 3.2)
via a new utf8
option, so you don't have to configure it through the generic
options
metadata. The following example shows the difference when using each
of the supported formats to configure routes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | // PHP Annotations
/**
- * @Route("/category/{name}", name="category", options={"utf8": true})
+ * @Route("/category/{name}", name="category", utf8=true)
*/
public function category()
// YAML
category:
path: /category/{name}
controller: App\Controller\DefaultController::category
- options:
- utf8: true
+ utf8: true
// XML
- <route id="category" path="/category/{name}"
- controller="App\Controller\DefaultController::category">
- <option key="utf8">true</option>
- </route>
+ <route id="category" path="/category/{name}"
+ controller="App\Controller\DefaultController::category"
+ utf8="true" />
|
In addition, we've added two new route options called locale
and format
to configure the default value of the special routing parameters _locale
and
_format
:
- Annotations
1 2 3 4 5 6
// src/Controller/BlogController.php /** * @Route("/category/{name}", name="category", format="json", locale="fr") */ public function category()
- YAML
1 2 3 4 5
# config/routes.yaml category: path: /category/{name} locale: fr format: json
- XML
1 2 3 4 5 6 7 8 9 10 11 12
<!-- config/routes.xml --> <?xml version="1.0" encoding="UTF-8" ?> <routes xmlns="http://symfony.com/schema/routing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd"> <route id="category" path="/category/{name}" controller="App\Controller\BlogController::category" format="json" locale="fr" /> </routes>
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
New in Symfony 4.3: Simpler Routing Options Config symfony.com/index.php/blog/new-in-symfony-4-3-simpler-routing-options-config
Tweet thisComments
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.