名称 最后更新
..
Annotation 正在载入提交数据...
DependencyInjection 正在载入提交数据...
Exception 正在载入提交数据...
Generator 正在载入提交数据...
Loader 正在载入提交数据...
Matcher 正在载入提交数据...
Alias.php 正在载入提交数据...
CHANGELOG.md 正在载入提交数据...
CompiledRoute.php 正在载入提交数据...
LICENSE 正在载入提交数据...
README.md 正在载入提交数据...
RequestContext.php 正在载入提交数据...
RequestContextAwareInterface.php 正在载入提交数据...
Route.php 正在载入提交数据...
RouteCollection.php 正在载入提交数据...
RouteCollectionBuilder.php 正在载入提交数据...
RouteCompiler.php 正在载入提交数据...
RouteCompilerInterface.php 正在载入提交数据...
Router.php 正在载入提交数据...
RouterInterface.php 正在载入提交数据...
composer.json 正在载入提交数据...

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