34 lines
963 B
Markdown
34 lines
963 B
Markdown
|
Routing Component
|
||
|
=================
|
||
|
|
||
|
The Routing component is a way to associate a Request with the code that will
|
||
|
convert it somehow to a Response. The example below demonstrates that with only
|
||
|
10 lines of code, you can set up a fully working routing system:
|
||
|
|
||
|
```
|
||
|
use Symfony\Component\HttpFoundation\Request;
|
||
|
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||
|
use Symfony\Component\Routing\RequestContext;
|
||
|
use Symfony\Component\Routing\RouteCollection;
|
||
|
use Symfony\Component\Routing\Route;
|
||
|
|
||
|
$routes = new RouteCollection();
|
||
|
$routes->add('hello', new Route('/hello', array('controller' => 'foo')));
|
||
|
|
||
|
$context = new RequestContext();
|
||
|
|
||
|
// this is optional and can be done without a Request instance
|
||
|
$context->fromRequest(Request::createFromGlobals());
|
||
|
|
||
|
$matcher = new UrlMatcher($routes, $context);
|
||
|
|
||
|
$parameters = $matcher->match('/hello');
|
||
|
```
|
||
|
|
||
|
Resources
|
||
|
---------
|
||
|
|
||
|
Unit tests:
|
||
|
|
||
|
https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Component/Routing
|