search
HomePHP FrameworkThinkPHPAnalyze the differences between TP6's multi-applications and TP5

The followingthinkphp frameworkThe tutorial column will explain and analyze the differences between TP6's multi-applications and TP5. I hope it will be helpful to friends in need!

What is the difference between the new "multi-application" added in ThinkPHP6 and ThinkPHP5?

First look at the directory structure of the multi-application in the official ThinkPHP6 manual:

├─app 应用目录
│  ├─index              主应用
│  │  ├─controller      控制器目录
│  │  ├─model           模型目录
│  │  ├─view            视图目录
│  │  ├─config          配置目录(优先)
│  │  └─ ...            更多类库目录
│  ├─admin              后台应用
│  │  ├─controller      控制器目录
│  │  ├─model           模型目录
│  │  ├─view            视图目录
│  │  ├─config          配置目录(优先)
│  │  └─ ...            更多类库目录
│
├─public                WEB目录(对外访问目录)
│  ├─admin.php          后台入口文件
│  ├─index.php          入口文件
│  ├─router.php         快速测试文件
│  └─.htaccess          用于apache的重写
│
├─config                应用配置目录
│  ├─index              index应用配置
│  └─admin              admin应用配置
│
├─view                视图目录
│  ├─index              index应用视图目录
│  └─admin              admin应用视图目录
│
├─route                 路由定义目录
│  ├─index              index应用路由定义目录
│  └─admin              admin应用路由定义目录
│
├─runtime               运行时目录
│  ├─index              index应用运行时目录
│  └─admin              admin应用运行时目录

In this way, the multi-application of ThinkPHP6 is nothing more than this. There is a front-end index application and a back-end admin application. This is called multi-application. Back then, when we used ThinkPHP5, we also developed the front-end application index and the back-end application admin. What's the difference?

Difference 1: It must be downloaded through composer before it can be used.

ThinkPHP6 framework is a single application after downloading by default. If you want to use multiple applications, you must download:

composer require topthink/think-multi-app

Difference 2: The routing definition must be under the current application.

We know that in ThinkPHP5, we can define the route file in the root directory, but after ThinkPHP6, the route must be defined in the application directory.

Difference 3: ThinkPHP6 supports application entry.

In ThinkPHP6, we can set a separate entry file for an application. For example, for the admin application, I can set the admin.php entry file to access it.

Difference 4: Domain name binding application.

For example, in ThinkPHP5, after we define the route of www.a.com/index/index..., we can achieve the effect of www.a.com/company.htm...

But Thinking about PHP6, you will find that no matter how you set the routing, the index application cannot be removed. It is always www.a.com/index/compa... How can this be fixed?

Then the solution can be to use the domain name binding application. We define the binding of the domain name and the application in the config/app.php configuration file, as follows:

'domain_bind' => [
'www.a.com' => 'index', // 域名绑定到www应用
'admin.a.com' => 'admin', // admin绑定到后台应用
],

In this way we You can use www.a.com/company.htm… to visit.

Finally:

In general, the multi-application of ThinkPHP6 is still a big improvement compared to ThinkPHP5, although it is a little troublesome to use for the first time and requires composer downloading. , but this does not affect our favor for ThinkPHP6 multi-applications.

Recommended: "The latest 10 thinkphp video tutorials"

The above is the detailed content of Analyze the differences between TP6's multi-applications and TP5. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:juejin. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),