@@ -666,6 +666,51 @@ URL Route Parameters
666
666
contains a collection of commonly used regular-expression constants such as
667
667
digits, dates and UUIDs which can be used as route parameter requirements.
668
668
669
+ .. configuration-block ::
670
+
671
+ .. code-block :: php-attributes
672
+
673
+ // src/Controller/BlogController.php
674
+ namespace App\Controller;
675
+
676
+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
677
+ use Symfony\Component\HttpFoundation\Response;
678
+ use Symfony\Component\Routing\Attribute\Route;
679
+ use Symfony\Component\Routing\Requirement\Requirement;
680
+
681
+ class BlogController extends AbstractController
682
+ {
683
+ #[Route('/blog/{page}', name: 'blog_list', requirements: ['page' => Requirement::DIGITS])]
684
+ public function list(int $page): Response
685
+ {
686
+ // ...
687
+ }
688
+ }
689
+
690
+ .. code-block :: yaml
691
+
692
+ # config/routes.yaml
693
+ blog_list :
694
+ path : /blog/{page}
695
+ controller : App\Controller\BlogController::list
696
+ requirements :
697
+ page : !php/const Symfony\Component\Routing\Requirement\Requirement::DIGITS
698
+
699
+ .. code-block :: php
700
+
701
+ // config/routes.php
702
+ use App\Controller\BlogController;
703
+ use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
704
+ use Symfony\Component\Routing\Requirement\Requirement;
705
+
706
+ return static function (RoutingConfigurator $routes): void {
707
+ $routes->add('blog_list', '/blog/{page}')
708
+ ->controller([BlogController::class, 'list'])
709
+ ->requirements(['page' => Requirement::DIGITS])
710
+ ;
711
+ // ...
712
+ };
713
+
669
714
.. versionadded :: 6.1
670
715
671
716
The ``Requirement `` enum was introduced in Symfony 6.1.
0 commit comments