The difference between ThinkPHP5 and ThinkPHP6

Author: Chen Jinjian
personal blog: HTTPS: //jian1098.github.io
CSDN blog: https: //blog.csdn.net/c_jian
Jane book: https: //www.jianshu.com/u/8ba9ac5706b6
Contact: jian1098 @qq.com

1. Installation method

thinkphp6 can only be composerinstalled by

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer		# 设置composer为阿里云镜像,解决国内使用composer慢的问题
composer create-project topthink/think myproject			# 安装稳定版,myproject为你的项目名

2. Configuration file

Thinkphp5 has config.phpbeen split into app、cache、database、routeother modules and placed in configfolders;

thinkphp6 has introduced a new .envfile, you can read this environment setting to configure the database, etc.

3. Bring your own web service

php think runYou can directly start a web server locally, and you can also -pspecify the port with parameters

4. Directory structure

applicationRename the folder to app;

The core framework of thinkphpthinkphp5 is under the project root directory , thinkphp6 isvendor/topthink

5. Controller

Previously inherited think\Controllerclasses, now inheritedBaseController

6. Cross-domain

You only need middleware.phpto register in \think\middleware\AllowCrossDomainto solve cross-domain issues

7. Component independence

Standalone ORM

Independent template engine

8. Strict mode

thinkphp6 uses php7 strict mode

9. Introduce Filesystem

10. Support multi-application entry

The admin application can set the admin.phpentry file to access; the api application can set the api.phpentry file to access.

If you want to use multi-application mode, you need to install the multi-application mode extension

composer require topthink/think-multi-app

Then your application directory structure needs to be adjusted as follows. The main difference is that an application subdirectory is added to the app directory, and then the configuration file and route definition file are included in the application directory

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

Supports access to multiple applications in the same entry file, and supports application mapping and customization. If you index.phpaccess it through the entry file and no application is set name, the system automatically adopts the automatic multi-application mode.

The URL address of the automatic multi-application mode is used by default

// 访问admin应用
http://serverName/index.php/admin
// 访问shop应用
http://serverName/index.php/shop

Through app.phpthe configuration file default_appconfiguration parameter specifies the default application

// 设置默认应用名称
'default_app' => 'home',

11. Domain name binding application

config/app.php The binding of the domain name and the application is defined in the configuration file

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

12. Automatic loading

thinkphp5 truly realizes on-demand loading, all class libraries adopt automatic loading mechanism, and support class library mapping and automatic loading of composer class library;

thinkphp6 uses composer to implement class automatic loading

Guess you like

Origin blog.csdn.net/C_jian/article/details/108184038