The Routing component converts the HTTP request to a series of configuration parameters.
Installation
You have two ways to install this component:
通过 Composer (symfony/routing on Packagist);使用官方的 Git repository (https://github.com/symfony/Routing)。
Then, you need to composer vendor/autoload.php this file to autoloading mechanism. Otherwise, your application will not find this component.
Usage
You need the following three sections to set up the basic routing system:
- RouteCollection, containing the definition of the route (instances of the class route)
- RequestContext, information about the request;
- Urlmatcher, match request to a single route (that is, make sure you need to use that route)
Here's a simple example. Here you need to make sure that your autoloader has loaded this component:
UseSymfony\Component\Routing\Matcher\Urlmatcher; UseSymfony\Component\Routing\RequestContext; UseSymfony\Component\Routing\routecollection; UseSymfony\Component\Routing\Route;$route=NewRoute ('/foo ',Array(' Controller '=' Mycontroller '));$routes=NewRouteCollection ();$routes->add (' Route_name ',$route);$context=NewRequestContext ($_server[' Request_uri ']);$matcher=NewUrlmatcher ($routes,$context);$parameters=$matcher->match ('/foo ');//Array (' controller ' = ' Mycontroller ', ' _route ' = ' route_name ')
It is important to note that when you use $_server[' Request_uri '], you can include any parameters on the URL. A simple solution is to use Httpfoundation component this component, which will be explained later in this article.
Not to be continued
Original link:
Http://symfony.com/doc/current/components/routing/introduction.html
The above describes the Symfony routing component (the Routing Component), including aspects of the content, I hope to be interested in PHP tutorial friends helpful.