PHP Classes

File: vendor/symfony/routing/README.md

Recommend this page to a friend!
  Classes of Adeleye Ayodeji   Simple PHP Chat with Websocket   vendor/symfony/routing/README.md   Download  
File: vendor/symfony/routing/README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Simple PHP Chat with Websocket
Implements a chat system using Websockets
Author: By
Last change:
Date: 15 hours ago
Size: 1,527 bytes
 

Contents

Class file image Download

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

* Documentation * Contributing * Report issues and send Pull Requests in the main Symfony repository