Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

symfony/routing v7.0.3

Maps an HTTP request to a set of configuration variables
Package summary
Share
0
issues
0
licenses
Package created
16 Oct 2011
Version published
30 Jan 2024
Maintainers
1
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does symfony/routing do?

As an essential component of the renowned Symfony framework, the symfony/routing package associates an HTTP request with a set of configuration variables. This allows developers to handle routing for their PHP applications effectively. This feature enhances the flexibility of URL creation and supports generating URLs dynamically based on various parameters.

How do you use symfony/routing?

You can incorporate symfony/routing into your projects with a two-step process. First, install the package via Composer, the PHP package manager, with the command: $ composer require symfony/routing.

The subsequent code illustrates how to use the Routing component in a PHP application:

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'

As demonstrated, you can create a new route, add it to the route collection, and subsequently use the UrlMatcher and UrlGenerator instances to match incoming requests and generate URLs respectively.

Where are the symfony/routing docs?

Comprehensive documentation for symfony/routing can be accessed at https://symfony.com/doc/current/routing.html. The guide contains step-by-step instructions, code examples, and other useful information to help you understand and implement this routing functionality successfully. Take advantage of this resource to learn more about routing in the Symfony framework and ensure its effective use in meeting your application's specific requirements.