URL management component mainly provides 2 functions:
1. According to the URL entered by the user, parse out the route for processing this request - which Action of which Controller handles it, and at the same time add the parameter part in the URL to in the $_GET parameter. In every web framework, such a component is needed to perform route distribution work.
2. Create a url based on the route and parameter array. The URL can be hard-coded in the view layer, that is, the URL address is written directly, but this often lacks flexibility and brings costs to 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+>/'=>'<controller>/', ), ), );</action></controller></action:\w+></controller:\w+></title:.*?></id:\d+></key></cate></p:\d+></id:\d+></key:\d+></cate:\w+>
The above is the configuration of a url management component, with a total of 3 rules. The figure below takes the first rule as an example to illustrate the two functions of url parsing and url creation. For each routing rule, CUrlManager will create a CUrlRule object to handle the two functions corresponding to this rule, so if there are several rules, there will be several CUrlRule objects. So CUrlRule is the core of url management. Let's analyze the working principle of CUrlRule.
Each url routing rule is processed by a CUrlRule object. Next, take the following routing rule as an example: '/art////'=>'article //', describes the processing process of url parsing and url creation. The process of processing URLs by each CUrlRule object can be divided into 3 stages:
1. Initializing the CUrlRule object
In the constructor of the CUrlRule object, 6 important member variables will be initialized:
2. Parse url
The work of parsing url is divided into three steps: a. Parse out each field in the url according to the pattern rules; b. Replace the reference fields in the route according to references. ;c. Add the fields specified in params to the $_GET array
3. Create url
The work of creating url is divided into three steps: a. According to the routePattern rules, parse out each field in the input route; b , merge the input parameter array and the array parsed in the previous step; c. Replace the template with the merged array.
The above is the Yii framework analysis (8) - the content of the URL management component. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
