Home  >  Article  >  Backend Development  >  What content has been upgraded in ThinkPHP 3.2 version_PHP Tutorial

What content has been upgraded in ThinkPHP 3.2 version_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:04:51671browse

What has been upgraded in ThinkPHP 3.2?

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:


App/Common/common.php => Application/Home/Common/function.php
App/Common/extend.php => Application/Home/Common/extend.php (assuming 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 => Application/Home/View

Note that because of the appearance of the Home directory, you need to modify your .htaccess file to

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]

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:


'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

ThinkPHP 3.2 has abandoned the following system configuration parameters

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

Modified the following configuration parameters

The code is as follows:


DEFAULT_MODULE => DEFAULT_CONTROLLER

5. Namespace

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:


namespace HomeAction;
use ThinkAction;

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:


namespace HomeEvent;
use ThinkAction;

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:


namespace HomeModel;
use ThinkModel;

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:


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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963995.htmlTechArticleWhat has been upgraded in ThinkPHP 3.2? ThinkPHP 3.2 has been released for a long time. Here is a summary of ThinkPHP 3.2 this time. What changes have taken place to facilitate development by programmers. Before...
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