Home > PHP Framework > ThinkPHP > body text

thinkphp5 upgrade steps

藏色散人
Release: 2019-11-09 09:33:35
Original
4580 people have browsed it

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');
Copy after login

is equivalent to

config('app.app_debug');
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!