Skip to content

symfony/routing

6.1
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

* 6.0:
  [HttpKernel] Fix empty request stack when terminating with exception
  [HttpKernel] Remove EOL when using error_log() in HttpKernel Logger
  [HttpClient] Add test case for seeking into the content of RetryableHttpClient responses
  [HttpClient] Fix buffering after calling AsyncContext::passthru()
  s/annd/and
  s/gargage/garbage
  [Console] Fix error output on windows cli
  Reserve keys when using numeric ones
  add missing Azerbaijani translations
  fix few typos/inconsistencies in latvian translations
  Fix TypeError in Router when using UrlGenerator
  [Messenger] Fix amqp socket lost
  fix: use message object from event
95effeb

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Jul 20, 2022
Nov 4, 2021

Routing Component

The Routing component maps an HTTP request to a set of configuration variables.

Getting Started

$ composer require symfony/routing
use App\Controller\BlogController;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

$route = new Route('/blog/{slug}', ['_controller' => BlogController::class]);
$routes = new RouteCollection();
$routes->add('blog_show', $route);

$context = new RequestContext();

// Routing can match routes with incoming requests
$matcher = new UrlMatcher($routes, $context);
$parameters = $matcher->match('/blog/lorem-ipsum');
// $parameters = [
//     '_controller' => 'App\Controller\BlogController',
//     'slug' => 'lorem-ipsum',
//     '_route' => 'blog_show'
// ]

// Routing can also generate URLs for a given route
$generator = new UrlGenerator($routes, $context);
$url = $generator->generate('blog_show', [
    'slug' => 'my-blog-post',
]);
// $url = '/blog/my-blog-post'

Resources