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应用运行时目录
(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
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绑定到后台应用 ],
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】
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!