diff --git a/routing.rst b/routing.rst index d6a2b59346c..b5480cf9b52 100644 --- a/routing.rst +++ b/routing.rst @@ -882,7 +882,8 @@ and in route imports. Symfony defines some special attributes with the same name .. code-block:: php-annotations // src/Controller/ArticleController.php - + namespace App\Controller; + // ... class ArticleController extends AbstractController { @@ -969,6 +970,9 @@ the controllers of the routes: .. code-block:: php-annotations + // src/Controller/BlogController.php + namespace App\Controller; + use Symfony\Component\Routing\Annotation\Route; class BlogController @@ -1039,6 +1043,9 @@ A possible solution is to change the parameter requirements to be more permissiv .. code-block:: php-annotations + // src/Controller/DefaultController.php + namespace App\Controller; + use Symfony\Component\Routing\Annotation\Route; class DefaultController @@ -1123,7 +1130,9 @@ the common configuration using options when importing the routes. .. configuration-block:: .. code-block:: php-annotations - + // src/Controller/BlogController.php + namespace App\Controller; + use Symfony\Component\Routing\Annotation\Route; /** @@ -1140,7 +1149,7 @@ the common configuration using options when importing the routes. } /** - * @Route("/{_locale}/posts/{slug}", name="post") + * @Route("/{_locale}/posts/{slug}", name="show") */ public function show(Post $post) { @@ -1216,7 +1225,7 @@ the common configuration using options when importing the routes. In this example, the route of the ``index()`` action will be called ``blog_index`` and its URL will be ``/blog/``. The route of the ``show()`` action will be called -``blog_post`` and its URL will be ``/blog/{_locale}/posts/{slug}``. Both routes +``blog_show`` and its URL will be ``/blog/{_locale}/posts/{slug}``. Both routes will also validate that the ``_locale`` parameter matches the regular expression defined in the class annotation. @@ -1832,6 +1841,8 @@ you only need to add an argument in the service constructor and type-hint it wit the :class:`Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface` class:: // src/Service/SomeService.php + namespace App\Service; + use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class SomeService @@ -1937,6 +1948,8 @@ generate URLs. This context can be configured globally for all commands: This information can be configured per command too:: // src/Command/SomeCommand.php + namespace App\Command; + use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; // ... @@ -2069,7 +2082,7 @@ each route explicitly: # config/routes.yaml login: path: /login - controller: App\Controller\SeurityController::login + controller: App\Controller\SecurityController::login schemes: [https] .. code-block:: xml