Skip to content
The Routing component maps an HTTP request to a set of configuration variables.
PHP
Branch: master
Clone or download

Latest commit

nicolas-grekas Merge branch '5.0'
* 5.0:
  [Lock] remove mention of mongodb
  [Routing] µtweaks
Latest commit 3ff0f4d Apr 12, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Annotation [Routing] Add stateless route attribute Feb 26, 2020
DependencyInjection Merge branch '3.4' into 4.1 Jan 16, 2019
Exception Allow \Throwable $previous everywhere Nov 12, 2019
Generator Merge branch '4.4' into 5.0 Jan 4, 2020
Loader Merge branch '5.0' Apr 12, 2020
Matcher [Routing][FrameworkBundle] Allow using env() in route conditions Feb 25, 2020
Tests Merge branch '5.0' Mar 30, 2020
.gitattributes add missing gitattributes for phpunit-bridge Mar 27, 2020
.gitignore Added missing files .gitignore Jul 21, 2013
CHANGELOG.md [Routing] Add stateless route attribute Feb 26, 2020
CompiledRoute.php Replace @return annotation by return type in final classes Jun 22, 2019
LICENSE Update year in license files Jan 1, 2020
README.md Add installation and minimal example to README Mar 28, 2020
RequestContext.php Merge branch '4.4' into 5.0 Nov 30, 2019
RequestContextAwareInterface.php [DI] minor docblock fixes Oct 24, 2017
Route.php Merge branch '4.4' into 5.0 Mar 12, 2020
RouteCollection.php Leverage trigger_deprecation() from symfony/deprecation-contracts Feb 8, 2020
RouteCollectionBuilder.php Leverage trigger_deprecation() from symfony/deprecation-contracts Feb 8, 2020
RouteCompiler.php Merge branch '5.0' Mar 16, 2020
RouteCompilerInterface.php [DI] minor docblock fixes Oct 24, 2017
Router.php Merge branch '4.4' into 5.0 Dec 12, 2019
RouterInterface.php [Routing] added a warning about the getRouteCollection() method Aug 4, 2019
composer.json Leverage PHP8's get_debug_type() Mar 16, 2020
phpunit.xml.dist Bump phpunit XSD version to 5.2 Nov 11, 2018

README.md

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

You can’t perform that action at this time.