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

How to understand thinkphp routing

藏色散人
Release: 2019-08-23 13:44:08
Original
3314 people have browsed it

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/...
Copy after login

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();
Copy after login

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

Set to enable in the configuration file

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template