symfony/routing

将HTTP请求映射到一组配置变量

安装次数: 570,519,502

依赖项: 1,534

建议者: 64

安全: 2

星标: 7,579

关注者: 27

分支: 98

v7.1.4 2024-08-29 08:16 UTC

This package is auto-updated.

Last update: 2024-09-21 10:39:57 UTC


README

路由组件将HTTP请求映射到一组配置变量。

入门指南

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'

赞助商

Symfony 7.1的路由组件由支持者 redirection.io

redirection.io记录您网站的所有HTTP流量,并允许您在几秒钟内通过重定向规则修复错误。为您的营销、SEO和IT团队提供有效的工具来管理网站流量!

通过赞助Symfony的开发来帮助Symfony!

资源