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