search
HomePHP FrameworkThinkPHPthinkphp5 upgrade steps
thinkphp5 upgrade stepsNov 09, 2019 am 09:33 AM
thinkphp5

thinkphp5 upgrade steps

ThinkPHP5.0 upgrade 5.1 full record

thinkphp5 upgrade steps

and split into App.php, cache.php and other independent configuration files, the system default configuration file list is as follows:

Because the project was developed with tp5.1, I found a good mall system online, but it was developed with 5.0 , so the 5 mall was upgraded to 5.1. There are many pitfalls in them, and they are recorded here for the benefit of future generations.

1. The first is the facade.

5.0 doesn’t have this thing. 5.1 new facade. Need to match the corresponding one in use. The corresponding table is as follows:

thinkphp5 upgrade steps

2. Configuration file adjustment

The original configuration file config.php is moved from the application directory to The config directory at the same level as the application directory is split into independent configuration files such as app.php and cache.php. The system default configuration file list is as follows:

thinkphp5 upgrade steps

instead In other words, all the original first-level configurations are independently configured as one configuration file

The configuration files under the original application extra directory are directly moved to the config directory.

The original module configuration files (including those under the extra directory) are directly moved to the config directory under the module, and then adjusted with reference to the application configuration file above.

5.1 configuration files all use the second-level configuration method. All parameters without the first-level configuration name will be used as the second-level configuration of the app. For example,

config('app_debug');

is equivalent to

config('app.app_debug');

3. Constant adjustment

5.1 All framework built-in constants have been canceled (does not affect custom constants in application code). If you need to obtain them, please use the built-in methods of the thinkacadeApp class and thinkacadeEnv Class acquisition, the following is the constant comparison table between 5.0 and 5.1:

4. Model adjustment

The data set query of the model always returns the data set object instead of Then the array;

If the primary key of the model's data table is not id, the pk attribute of the model must be set;

Soft delete trait introduction is changed to use thinkmodelconcernSoftDelete;

Global query There is no need to add soft deletion conditions in the scope base method;

The aggregation model function is abolished and replaced by the associated model with the associated automatic writing function, which is more flexible;

The query scope of the model only needs to be called after the scope method is called. You can use the query method of the database;

Cancel the data verification function of the model, please use controller verification or routing verification instead;

This model adjustment must be carefully considered. For example, the primary key in the second point. The mall system uses a large number of association models. No matter what the name of the primary key in the data table is, it can be automatically obtained in the 5.0 era. However, in 5.1, the default is id. You must use $pk=user_id to specify the primary key name, otherwise it will report " The error "Model attribute does not exist" troubled me for 2 hours.

5. Controller adjustment

_initialize method was changed to initialize (it deceived me for an hour, anyone who doesn’t have good eyesight will be deceived)

6. Don’t forget the last step: clear all files in the cache directory

7. For other matters, it is recommended to read the TP5.1 documentation in detail and don’t miss a word.

Recommended learning: thinkphp5

The above is the detailed content of thinkphp5 upgrade steps. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
宝塔部署thinkphp5报错怎么办宝塔部署thinkphp5报错怎么办Dec 19, 2022 am 11:04 AM

宝塔部署thinkphp5报错的解决办法:1、打开宝塔服务器,安装php pathinfo扩展并启用;2、配置“.access”文件,内容为“RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]”;3、在网站管理里面,启用thinkphp的伪静态即可。

thinkphp5 post得不到值怎么办thinkphp5 post得不到值怎么办Dec 06, 2022 am 09:29 AM

thinkphp5 post得不到值是因为TP5是通过strpos函数在Header的content-type值中查找app/json字符串的,其解决办法就是设置Header的content-type值为app/json即可。

thinkphp5怎么获取请求过来的网址thinkphp5怎么获取请求过来的网址Dec 20, 2022 am 09:48 AM

thinkphp5获取请求网址的方法:1、使用“\think\Request”类的“$request = Request::instance();”方法获取当前的url信息;2、通过自带的助手函数“$request->url()”获取包含域名的完整URL地址。

thinkphp5 url重写不行怎么办thinkphp5 url重写不行怎么办Dec 12, 2022 am 09:31 AM

thinkphp5 url重写不行的解决办法:1、查看httpd.conf配置文件中是否加载了mod_rewrite.so模块;2、将AllowOverride None中的None改为All;3、修改Apache配置文件.htaccess为“RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]”保存即可。

怎么去除thinkphp5标题栏icon怎么去除thinkphp5标题栏iconDec 20, 2022 am 09:24 AM

去除thinkphp5标题栏icon的方法:1、找到thinkphp5框架public下的favicon.ico文件;2、删除该文件或者选择另一张图片命名改为favicon.ico,并替换原favicon.ico文件即可。

thinkphp5提示控制器不存在怎么办thinkphp5提示控制器不存在怎么办Dec 06, 2022 am 10:43 AM

thinkphp5提示控制器不存在的解决办法:1、检查对应的控制器里面的命名空间是否写对,修改为正确的命名空间;2、打开相应的tp文件,修改类名即可。

ThinkPHP5怎么查询昨天的数据ThinkPHP5怎么查询昨天的数据Dec 05, 2022 am 09:20 AM

ThinkPHP5查询昨天数据的方法:1、打开ThinkPHP5相关文件;2、通过表达式“db('table')->whereTime('c_time', 'yesterday')->select();”查询昨天的数据即可。

thinkphp5报错提示怎么设置thinkphp5报错提示怎么设置Dec 07, 2022 am 10:31 AM

thinkphp5设置报错提示的方法:1、进入项目根目录下的public文件夹,打开index.php入口文件;2、查看调试模式开关的注释;3、将“APP_DEBUG”常量的值调整为true即可展示错误信息提示。

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!