Skip to content

Commit ebfa5e2

Browse files
committed
[Routing] Add example of Requirement enum
1 parent 2685f38 commit ebfa5e2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

routing.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,51 @@ URL Route Parameters
666666
contains a collection of commonly used regular-expression constants such as
667667
digits, dates and UUIDs which can be used as route parameter requirements.
668668

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+
669714
.. versionadded:: 6.1
670715

671716
The ``Requirement`` enum was introduced in Symfony 6.1.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy