8000 minor #36246 [Routing] Add installation and minimal example to README… · enflow/symfony@d33392f · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 10, 2022. It is now read-only.

Commit d33392f

Browse files
committed
minor symfony#36246 [Routing] Add installation and minimal example to README (wouterj)
This PR was merged into the 4.4 branch. Discussion ---------- [Routing] Add installation and minimal example to README | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | symfony/symfony-docs#13431 Similair to what I did in symfony#35552, this PR updates the README of the Routing component to include a minimal example and installation command. Commits ------- be66120 Add installation and minimal example to README
2 parents 38cbcc6 + be66120 commit d33392f

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)
0