Symfony routing Component (the Routing Component)

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.