2121c55b02
* 5.0: [VarDumper] fix typo Fix support for PHP8 union types [FrameworkBundle] preserve dots in query-string when redirecting [3.4] Fix support for PHP8 union types [PhpUnitBridge] Streamline ansi/no-ansi of composer according to phpunit --colors option [3.4] Small update in our internal terminology [Cache] fix compat with DBAL v3 [HttpClient] Convert CurlHttpClient::handlePush() to instance method [VarDumper] Fix CliDumper coloration [DI] tighten detection of local dirs to prevent false positives [FrameworkBundle] preserve dots in query-string when redirecting Fix precendence in 4.4 bumped Symfony version to 3.4.43 updated VERSION for 3.4.42 update CONTRIBUTORS for 3.4.42 updated CHANGELOG for 3.4.42 |
||
---|---|---|
.. | ||
Annotation | ||
DependencyInjection | ||
Exception | ||
Generator | ||
Loader | ||
Matcher | ||
Tests | ||
.gitattributes | ||
.gitignore | ||
CHANGELOG.md | ||
CompiledRoute.php | ||
composer.json | ||
LICENSE | ||
phpunit.xml.dist | ||
README.md | ||
RequestContext.php | ||
RequestContextAwareInterface.php | ||
Route.php | ||
RouteCollection.php | ||
RouteCollectionBuilder.php | ||
RouteCompiler.php | ||
RouteCompilerInterface.php | ||
Router.php | ||
RouterInterface.php |
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'