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 of things to deal with for grouping. Here is just an introduction to the ungrouped situation. Friends who have done grouping, 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.
Copy code The code is as follows:
App/Common/common.php => Application/Home/Common/function.php
App/Common/extend.php => Application/Home/Common/extend.php (assuming a definition exists)
App/Conf/Config.php => Application/Home/Conf/config.php
App/Lang/zh-cn/common.php => Application/Home/Lang/zh-cn.php (assuming it exists)
App/Lib/Action => Application/Home/Action
App/Lib/Model => Application/Home/Model
App/Tpl =>
Copy code The code is as follows:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/home/$1 [QSA,PT,L]
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:
Copy code The code is as follows:
'DEFAULT_C_LAYER' => 'Action', // Default controller layer name
'MODULE_ALLOW_LIST' => array('Home','Admin',...), // Configure your original group list
'DEFAULT_MODULE' => 'Home', // Configure your original default group
4. Changes in system configuration parameters
Copy code The code is as follows:
APP_GROUP_LIST
APP_GROUP_MODE
APP_AUTOLOAD_PATH
APP_TAGS_ON
APP_GROUP_PATH
DEFAULT_APP
DEFAULT_GROUP
VAR_GROUP
LOG_DEST
LOG_EXTRA
Copy code The code is as follows:
DEFAULT_MODULE => DEFAULT_CONTROLLER
5. Namespace
Copy code The code is as follows:
namespace HomeAction;
use ThinkAction;
Copy code The code is as follows:
namespace HomeEvent;
use ThinkAction;
Copy code The code is as follows:
namespace HomeModel;
use ThinkModel;
Copy code The code is as follows:
namespace HomeService;
use ThinkModel;
6. Method adjustment
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.