

GitHub - symfony/routing: [READ-ONLY] Subtree split of the Symfony Routing Compo...
source link: https://github.com/symfony/routing
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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
Recommend
-
103
symfony/polyfill-mbstring: This component provides a partial, native PHP implementation for the Mbstring extension. Sk...
-
148
symfony/phpunit-bridge: Provides utilities for PHPUnit, especially user deprecation notices management. Skip to content
-
144
symfony/console: The Console component eases the creation of beautiful and testable command line interfaces. Skip to content...
-
111
symfony/debug: The Debug component provides tools to ease debugging PHP code. This repository has been archived by the owner...
-
122
symfony/finder: The Finder component finds files and directories via an intuitive fluent interface. Skip to content...
-
133
Process Component The Process component executes commands in sub-processes. Sponsor The Process component for Symfony 6.1 is backed by
-
139
symfony/filesystem: The Filesystem component provides basic utilities for the filesystem. Skip to content...
-
91
symfony/http-kernel: The HttpKernel component provides a structured process for converting a Request into a Response. Skip to co...
-
156
symfony/var-dumper: The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. It provides a better dump() function that you can use instead of var_dump().
-
77
Translation Component The Translation component provides tools to internationalize your application. Getting Started $ composer require symfony/translation use Symfony\Component\...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK