Home  >  Article  >  PHP Framework  >  Where is the routing of yii framework?

Where is the routing of yii framework?

(*-*)浩
(*-*)浩Original
2019-12-14 10:20:312824browse

Where is the routing of yii framework?

When a YII application starts processing a request, the first thing it needs to do is convert the requested URL into a route. The role of routing is to subsequently instantiate corresponding controllers and operations in order to process requests. The entire processing process is called routing.

The reverse process of routing is called URL generation, which refers to using the given routing and parameter information to generate a URL.                                                                                                                                                                                                                              (Recommended learning: yii framework)

When using the generated URL to make a request, the routing processing process can parse it again and restore the original routing and parameter information.

The URL manager is mainly responsible for routing and URL generation, which is registered as an application component.

The URL manager provides the method parseRequest() to parse the request and parse out the routing and parameter information. The method createUrl() is used to generate a URL from the given route and parameter information. By configuring the URL manager in the application configuration, your application can recognize any URL format without modifying the existing program code.

For example, you can use the following code to generate a URL.

use yii\helpers\Url;
// Url::to() calls UrlManager::createUrl() to create a URL
$url = Url::to(['post/view', 'id' => 100]);

Depending on the configuration of the URL manager, the URL generated by the above code will look like the following.

If this URL is requested subsequently, it will be parsed into the original route and parameter information above.

/index.php?r=post/view&id=100
/index.php/post/100
/posts/100

Default route

When a request does not find a matching route, the so-called default route will be used instead. By default, the default route is site/index, which points to the action index under the controller site. You can also specify it by modifying the defaultRoute property in the application configuration, like this:

[
    // ...
    'defaultRoute' => 'main/index',
];

The above is the detailed content of Where is the routing of yii framework?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn