b912af9261
* 5.1: Fix typo Fix deprecated libxml_disable_entity_loader Add Tagalog translations for validator messages 94, 95, 96 and 99 PHPUnit's assertContains() performs strict comparisons now. [ClassLoader][Routing] Fix namespace parsing on php 8. Fix deprecated libxml_disable_entity_loader Made reference to PHPUnit\Util\XML::loadfile php5-compatible. [Validator] Add missing translations for german and vietnamese Modernized deprecated PHPUnit assertion calls [Console] The message of "class not found" errors has changed in php 8. The PHPUnit\Util\XML class has been removed in PHPUnit 9.3. [Console] Make sure we pass a numeric array of arguments to call_user_func_array(). Remove outdated references from base_js.html.twig file [String] We cannot have a "provides" function in test cases. Typo: somes styles fixed [Serializer] Fix that it will never reach DOMNode [Validator] sync translations [VarDumper] Improve previous fix on light array coloration [Cache] Fix #37667 |
||
---|---|---|
.. | ||
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'