Home >PHP Framework >ThinkPHP >Analyze the differences between TP6's multi-applications and TP5

Analyze the differences between TP6's multi-applications and TP5

藏色散人
藏色散人forward
2021-11-12 14:42:294369browse

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.im. If there is any infringement, please contact admin@php.cn delete