Home PHP Framework ThinkPHP What is the difference between ThinkPHP6's new 'Multiple Applications” and ThinkPHP5?

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

Apr 30, 2020 am 10:18 AM
thinkphp5 thinkphp6

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!

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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I get an error when deploying thinkphp5 in Pagoda? What should I do if I get an error when deploying thinkphp5 in Pagoda? Dec 19, 2022 am 11:04 AM

Solution to the error reported when deploying thinkphp5 in Pagoda: 1. Open the Pagoda server, install the php pathinfo extension and enable it; 2. Configure the ".access" file with the content "RewriteRule ^(.*)$ index.php?s=/$1 [QSA ,PT,L]”; 3. In website management, just enable thinkphp’s pseudo-static.

What should I do if thinkphp5 url rewriting fails? What should I do if thinkphp5 url rewriting fails? Dec 12, 2022 am 09:31 AM

Solution to thinkphp5 url rewriting not working: 1. Check whether the mod_rewrite.so module is loaded in the httpd.conf configuration file; 2. Change None in AllowOverride None to All; 3. Modify the Apache configuration file .htaccess to "RewriteRule ^ (.*)$ index.php [L,E=PATH_INFO:$1]" and save it.

How to get the requested URL in thinkphp5 How to get the requested URL in thinkphp5 Dec 20, 2022 am 09:48 AM

Methods for thinkphp5 to obtain the requested URL: 1. Use the "$request = Request::instance();" method of the "\think\Request" class to obtain the current URL information; 2. Use the built-in helper function "$request-> url()" to obtain the complete URL address including the domain name.

What should I do if thinkphp5 post cannot get the value? What should I do if thinkphp5 post cannot get the value? Dec 06, 2022 am 09:29 AM

thinkphp5 post cannot get a value because TP5 uses the strpos function to find the app/json string in the content-type value of the Header. The solution is to set the content-type value of the Header to app/json.

How to remove thinkphp5 title bar icon How to remove thinkphp5 title bar icon Dec 20, 2022 am 09:24 AM

How to remove the thinkphp5 title bar icon: 1. Find the favicon.ico file under the thinkphp5 framework public; 2. Delete the file or choose another picture to rename it to favicon.ico and replace the original favicon.ico file.

What to use to replace iframe in thinkphp6 What to use to replace iframe in thinkphp6 Nov 24, 2023 pm 03:54 PM

Ajax and front-end frameworks can be used instead of iframes. Detailed introduction: 1. Use Ajax to obtain the data returned by the server through asynchronous requests, and then use JavaScript to insert the data into the specified DOM element to achieve partial refresh. You can use jQuery's $.ajax() method or the native XMLHttpRequest object to send Ajax requests; 2. Use popular front-end frameworks to more efficiently manage the status and components of the page and achieve dynamic loading and updating of content.

What should I do if thinkphp5 prompts that the controller does not exist? What should I do if thinkphp5 prompts that the controller does not exist? Dec 06, 2022 am 10:43 AM

Solution to thinkphp5 prompting that the controller does not exist: 1. Check whether the namespace in the corresponding controller is written correctly and change it to the correct namespace; 2. Open the corresponding tp file and modify the class name.

A brief analysis of how to use workerman in thinkphp6 [tutorial sharing] A brief analysis of how to use workerman in thinkphp6 [tutorial sharing] Dec 08, 2022 pm 08:30 PM

How to use workererman in thinkphp6? The following article will introduce you to the tutorial on integrating workerman with thinkphp6. I hope it will be helpful to you.

See all articles