Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] add priority option to annotated routes #13113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,54 @@ parameter:
To give a ``null`` default value to any parameter, add nothing after the
``?`` character (e.g. ``/blog/{page?}``).

Priority Parameter
~~~~~~~~~~~~~~~~~~

.. versionadded:: 5.1

The ``priority`` parameter was introduced in Symfony 5.1

When defining a greedy pattern that matches many routes, this may be at the
beginning of your routing collection and prevents any route defined after to be
matched.
A ``priority`` optional parameter is available in order to let you choose the
order of your routes, and it is only available when using annotations.

.. code-block:: php-annotations

// src/Controller/BlogController.php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class BlogController extends AbstractController
{
/**
* This route has a greedy pattern and is defined first.
*
* @Route("/blog/{slug}", name="blog_show")
*/
public function show(string $slug)
{
// ...
}

/**
* This route could not be matched without defining a higher priority than 0.
*
* @Route("/blog/list", name="blog_list", priority=2)
*/
public function list()
{
// ...
}
}

The priority parameter expects an integer value. Routes with higher priority
are sorted before routes with lower priority. The default value when it is not
defined is ``0``.

Parameter Conversion
~~~~~~~~~~~~~~~~~~~~

Expand Down