Home > PHP Framework > ThinkPHP > body text

What is the difference between ThinkPHP6's new 'Multiple Applications” and ThinkPHP5?

王雪芹
Release: 2020-04-30 10:48:17
Original
2941 people have browsed it

In ThinkPHP6, a new term called "multi-application" has been added. This is not available in ThinkPHP5, so what does this do? Come and listen to Wang Xueqin, the contributor to PHP Chinese website, chattering...

First, take a look at the official ThinkPHP6 manual about the directory structure of multiple applications:

├─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应用运行时目录
Copy after login

(Source: ThinkPHP6.0 Rapid Development Manual (Case Version))

Oh, at first glance, 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 by default after downloading. If you want to use multiple applications, you must download:

composer require topthink/think-multi-app
Copy after login

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/company.html, we can achieve this effect www.a.com/company.html

But in ThinkPHP6, you will find that no matter how you set up the routing, the index application cannot be removed. It is always www.a.com/index/company.html. 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绑定到后台应用
],
Copy after login

In this way we It can be accessed using www.a.com/company.html.

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 Tutorial】

1. thinkphp technical article

2. thinkphp video tutorial

The above is the detailed content of What is the difference between ThinkPHP6's new 'Multiple Applications” and ThinkPHP5?. 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