8000 feature #13113 [Routing] add priority option to annotated routes (MrY… · symfony/symfony-docs@e0b177e · GitHub
[go: up one dir, main page]

Skip to content

Commit e0b177e

Browse files
committed
feature #13113 [Routing] add priority option to annotated routes (MrYamous)
This PR was merged into the master branch. Discussion ---------- [Routing] add priority option to annotated routes PR for issue #13059 Commits ------- a67a59b add priority option to annotated routes
2 parents c11c397 + a67a59b commit e0b177e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

routing.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,54 @@ parameter:
798798
To give a ``null`` default value to any parameter, add nothing after the
799799
``?`` character (e.g. ``/blog/{page?}``).
800800

801+
Priority Parameter
802+
~~~~~~~~~~~~~~~~~~
803+
804+
.. versionadded:: 5.1
805+
806+
The ``priority`` parameter was introduced in Symfony 5.1
807+
808+
When defining a greedy pattern that matches many routes, this may be at the
809+
beginning of your routing collection and prevents any route defined after to be
810+
matched.
811+
A ``priority`` optional parameter is available in order to let you choose the
812+
order of your routes, and it is only available when using annotations.
813+
814+
.. code-block:: php-annotations
815+
816+
// src/Controller/BlogController.php
817+
namespace App\Controller;
818+
819+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
820+
use Symfony\Component\Routing\Annotation\Route;
821+
822+
class BlogController extends AbstractController
823+
{
824+
/**
825+
* This route has a greedy pattern and is defined first.
826+
*
827+
* @Route("/blog/{slug}", name="blog_show")
828+
*/
829+
public function show(string $slug)
830+
{
831+
// ...
832+
}
833+
834+
/**
835+
* This route could not be matched without defining a higher priority than 0.
836+
*
837+
* @Route("/blog/list", name="blog_list", priority=2)
838+
*/
839+
public function list()
840+
{
841+
// ...
842+
}
843+
}
844+
845+
The priority parameter expects an integer value. Routes with higher priority
846+
are sorted before routes with lower priority. The default value when it is not
847+
defined is ``0``.
848+
801849
Parameter Conversion
802850
~~~~~~~~~~~~~~~~~~~~
803851

0 commit comments

Comments
 (0)
0