Skip to content

Commit be66120

Browse files
committed
Add installation and minimal example to README
1 parent 3a6f02d commit be66120

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/Symfony/Component/Routing/README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,48 @@ Routing Component
33

44
The Routing component maps an HTTP request to a set of configuration variables.
55

6+
Getting Started
7+
---------------
8+
9+
```
10+
$ composer require symfony/routing
11+
```
12+
13+
```php
14+
use App\Controller\BlogController;
15+
use Symfony\Component\Routing\Generator\UrlGenerator;
16+
use Symfony\Component\Routing\Matcher\UrlMatcher;
17+
use Symfony\Component\Routing\RequestContext;
18+
use Symfony\Component\Routing\Route;
19+
use Symfony\Component\Routing\RouteCollection;
20+
21+
$route = new Route('/blog/{slug}', ['_controller' => BlogController::class]);
22+
$routes = new RouteCollection();
23+
$routes->add('blog_show', $route);
24+
25+
$context = new RequestContext();
26+
27+
// Routing can match routes with incoming requests
28+
$matcher = new UrlMatcher($routes, $context);
29+
$parameters = $matcher->match('/blog/lorem-ipsum');
30+
// $parameters = [
31+
// '_controller' => 'App\Controller\BlogController',
32+
// 'slug' => 'lorem-ipsum',
33+
// '_route' => 'blog_show'
34+
// ]
35+
36+
// Routing can also generate URLs for a given route
37+
$generator = new UrlGenerator($routes, $context);
38+
$url = $generator->generate('blog_show', [
39+
'slug' => 'my-blog-post',
40+
]);
41+
// $url = '/blog/my-blog-post'
42+
```
43+
644
Resources
745
---------
846

9-
* [Documentation](https://symfony.com/doc/current/components/routing.html)
47+
* [Documentation](https://symfony.com/doc/current/routing.html)
1048
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
1149
* [Report issues](https://github.com/symfony/symfony/issues) and
1250
[send Pull Requests](https://github.com/symfony/symfony/pulls)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy