Yii Framework Analysis (eight)--url management components

Source: Internet
Author: User
Tags yii

The URL management component provides 2 main features:
1, according to the user input URL, resolves the route to handle the request-which Controller's action to handle, while the URL of the parameter part of the $_get parameter. In each web framework, one such component is required for the work of routing distribution.
2. Create a URL based on the Routing and Parameter array. URLs can be hardcoded at the view level, which is a direct write to a dead URL, but this often lacks flexibility and costs for later maintenance.

Array (' Components    ' =>array ('        urlformat ' = ' path ',        ' rules ' =>array (            '/art/<cate:\w+ >/<key:\d+>/<id:\d+>/<p:\d+> ' = ' article/<cate>/<key> ',            ' post/<id:\d +>/<title:.*?> ' = ' post/view ',            ' <controller:\w+>/<action:\w+> ' = ' <controller >/<action> ',         ),)    ,);

As above is a configuration of a URL management component, a total of 3 rules. Taking the first rule as an example, the two functions of URL parsing and URL creation are explained. For each routing rule, Curlmanager creates a Curlrule object to handle the two functions that the rule corresponds to, so there are several rules that will have a few curlrule objects. So Curlrule is the core of URL management, and then analyze how Curlrule works.

Each URL routing rule is handled by a Curlrule object, followed by the following routing rule: '/art/<cate:\w+>/<key:\d+>/<id:\d+>/<p:\d+> ' = > ' article/<cate>/<key> ', which describes the process of URL parsing and URL creation. The process of handling URLs for each Curlrule object can be divided into 3 stages:
1. Initialize the Curlrule object
In the constructor of a Curlrule object, 6 important member variables are initialized:

2. Parsing URLs
The work of parsing the URL is divided into 3 steps: A, according to the pattern rules, parse out the URL of each field, B, according to References reference field in the replacement; C, add the field specified in the params to the $_get array
3. Create a URL
The work of creating a URL is divided into 3 steps: A, according to the Routepattern rules, parse out the input route of each field, B, the input parameter array and the previous step to parse the array to merge; C, replace the template with the merged array

Yii Framework Analysis (eight)--url management components

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.