Home  >  Article  >  PHP Framework  >  How to understand thinkphp routing

How to understand thinkphp routing

藏色散人
藏色散人Original
2019-08-23 13:44:083208browse

How to understand thinkphp routing

How to understand the routing of thinkphp?

thinkphp routing function is completed by \think\Route class.

Overview

Since the URL rules adopted by ThinkPHP5.0 by default are:

http://server/module/controller/action/param/value/...

The role of routing is to simplify the URL access address, and according to the defined Route types are parsed correctly.

The new version of the routing function has made a lot of enhancements, including:

● Supports routing to module controllers/operations, controller class methods, closure functions and redirect addresses, and even It is a method of any class library;

● Enhancement of closure routing;

● Rule routing supports global and local variable rule definitions (regular);

● Supports routing to Any level of controller;

● Subdomain name routing function improvement;

● Support routing grouping and group parameter definition;

● Add resource routing and nesting support;

● Supports using behaviors or custom functions to detect routing rules;

● ThinkPHP5.0 routing supports three methods of URL parsing rules.

The routing of 5.0 is for applications rather than for modules, so the routing settings are also for all modules under the application. If you want different modules to distinguish different settings (for example, some modules need to turn off routing, some modules Need to force routing, etc.), you need to add a separate entry file to the module and make the following modifications:

// 定义项目路径
define('APP_PATH', __DIR__ . '/../application/');
// 加载框架基础文件
require __DIR__ . '/../thinkphp/base.php';
// 绑定当前入口文件到admin模块
\think\Route::bind('admin');
// 关闭admin模块的路由
\think\App::route(false);
// 执行应用
\think\App::run()->send();

Starting from version V5.0.21, route resolution caching is supported.

Set to enable in the configuration file

    // 开启路由解析缓存
    'route_check_cache'      => true,

This article comes from the ThinkPHP framework technical article column: http://www.php.cn/phpkj/thinkphp/

The above is the detailed content of How to understand thinkphp routing. 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