8000 add priority option to annotated routes · symfony/symfony-docs@a67a59b · GitHub
[go: up one dir, main page]

Skip to content

Commit a67a59b

Browse files
MrYamousHeahDude
authored andcommitted
add priority option to annotated routes
1 parent ec50b76 commit a67a59b

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
@@ -794,6 +794,54 @@ parameter:
794794
To give a ``null`` default value to any parameter, add nothing after the
795795
``?`` character (e.g. ``/blog/{page?}``).
796796

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

0 commit comments

Comments
 (0)
0