Home >Backend Development >PHP Tutorial >What content has been upgraded in ThinkPHP 3.2 version_PHP Tutorial
ThinkPHP 3.2 has been released for a long time. Here is a summary of what changes have taken place in ThinkPHP 3.2 this time to facilitate programmers. development.
Foreword
ThinkPHP 3.2 is based on ThinkPHP 3.1 and has many changes. I think this version should be set as ThinkPHP 4.0 instead of 3.2. If you are using ThinkPHP 3.1, please do not migrate and upgrade rashly. This is not a matter of simply overwriting the files and leaving them safe.
1. PHP version
ThinkPHP 3.2 requires PHP 5.3 or above, while ThinkPHP 3.1 only requires PHP 5.2
2. Modification of program folder
ThinkPHP 3.2 uses Application as the program folder, while ThinkPHP 3.1 uses app as the program folder.
3. Upgrade of different group settings
It is recommended that you try not to do grouping in future development, otherwise there will be a lot to deal with for grouping. Here is just an introduction to the ungrouped situation. If you have grouped friends, please go to the official documentation to find the answer.
ThinkPHP 3.2 sets up a Home directory, and many files will be migrated to the Home directory.
The code is as follows:
Note that because of the appearance of the Home directory, you need to modify your .htaccess file to
The code is as follows:
Otherwise, a module not found error will occur.
The new directory renames Action and Tpl to Controller and View respectively, which more intuitively reflects the MVC folder deployment method. For those who have retained Action, you can modify the information in Application/Common/config.php:
The code is as follows:
ThinkPHP 3.2 has abandoned the following system configuration parameters
The code is as follows:
Modified the following configuration parameters
The code is as follows:
ThinkPHP 3.2 adds a namespace. Add the following code to the header of all files under the project's Application/Home/Action directory (must be the first line except comments):
The code is as follows:
If your project uses controller layering, you need to add similar code to each layered class library file. For example, if you define an Event layer, you need to add it in the header:
The code is as follows:
Add the following code to the header of all files under the project's Application/Home/Model directory (must be the first line except for comments):
The code is as follows:
If your project uses model layering, you need to add similar code to each layered class library file. For example, if you have a Service layer, you need to add:
The code is as follows:
The following methods of the controller class ThinkController or ThinkAction have been deprecated:
废除方法 | 替代方法 |
---|---|
_get('id') | I('get.id') |
_post('id') | I('post.id') |
_put('id') | I('put.id') |
_param('id') | I('id') |
_request('id') | I('request.id') |
_cookie('id') | I('cookie.id') |
7. Constant adjustment
The following constants have been deprecated:
APP_NAME // There is no need to define this constant in version 3.2
__GROUP__ // In version 3.2, you can use __MODULE__ to represent the URL address of the module
GROUP_NAME //In version 3.2, you can use MODULE_NAME to get the current module name
MODE_NAME // The mode extension in version 3.2 has been abandoned. Please refer to the mode adjustment section below
This basically completes the migration. If there are some modifications in the middle, please go to the official documentation to find the answer.
The above are the changes in ThinkPHP3.2 described in this article. I hope it can be helpful to everyone.