Skip to content

Maps an HTTP request to a set of configuration variables

License

Notifications You must be signed in to change notification settings

symfony/routing

Repository files navigation

Routing Component

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

Getting Started

composer require symfony/routing
useApp\Controller\BlogController;
useSymfony\Component\Routing\Generator\UrlGenerator;
useSymfony\Component\Routing\Matcher\UrlMatcher;
useSymfony\Component\Routing\RequestContext;
useSymfony\Component\Routing\Route;
useSymfony\Component\Routing\RouteCollection;

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

$context=newRequestContext();

// Routing can match routes with incoming requests
$matcher=newUrlMatcher($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=newUrlGenerator($routes,$context);
$url=$generator->generate('blog_show',[
'slug'=>'my-blog-post',
]);
// $url = '/blog/my-blog-post'

Sponsor

The Routing component for Symfony 7.1 isbackedbyredirection.io.

redirection.io logs all your website’s HTTP traffic, and lets you fix errors with redirect rules in seconds. Give your marketing, SEO and IT teams the right tool to manage your website traffic efficiently!

Help Symfony bysponsoringits development!

Resources