@@ -649,6 +649,51 @@ URL Route Parameters
649
649
contains a collection of commonly used regular-expression constants such as
650
650
digits, dates and UUIDs which can be used as route parameter requirements.
651
651
652
+ .. configuration-block ::
653
+
654
+ .. code-block :: php-attributes
655
+
656
+ // src/Controller/BlogController.php
657
+ namespace App\Controller;
658
+
659
+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
660
+ use Symfony\Component\HttpFoundation\Response;
661
+ use Symfony\Component\Routing\Attribute\Route;
662
+ use Symfony\Component\Routing\Requirement\Requirement;
663
+
664
+ class BlogController extends AbstractController
665
+ {
666
+ #[Route('/blog/{page}', name: 'blog_list', requirements: ['page' => Requirement::DIGITS])]
667
+ public function list(int $page): Response
668
+ {
669
+ // ...
670
+ }
671
+ }
672
+
673
+ .. code-block :: yaml
674
+
675
+ # config/routes.yaml
676
+ blog_list :
677
+ path : /blog/{page}
678
+ controller : App\Controller\BlogController::list
679
+ requirements :
680
+ page : !php/const Symfony\Component\Routing\Requirement\Requirement::DIGITS
681
+
682
+ .. code-block :: php
683
+
684
+ // config/routes.php
685
+ use App\Controller\BlogController;
686
+ use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
687
+ use Symfony\Component\Routing\Requirement\Requirement;
688
+
689
+ return static function (RoutingConfigurator $routes): void {
690
+ $routes->add('blog_list', '/blog/{page}')
691
+ ->controller([BlogController::class, 'list'])
692
+ ->requirements(['page' => Requirement::DIGITS])
693
+ ;
694
+ // ...
695
+ };
696
+
652
697
.. tip ::
653
698
654
699
Route requirements (and route paths too) can include
0 commit comments