What content has been upgraded to ThinkPHP 3.2 version, thinkphp3.2_PHP tutorial

WBOY
Release: 2016-07-13 10:05:29
Original
841 people have browsed it

What content has been upgraded to ThinkPHP 3.2 version, thinkphp3.2

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                                          =>

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

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]


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:

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

ThinkPHP 3.2 has abandoned the following 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

Modified the following configuration parameters

Copy code 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):

Copy code 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:

Copy code 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):

Copy code 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:

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963839.htmlTechArticleWhat has been upgraded to ThinkPHP 3.2 version? Thinkphp3.2 Preface ThinkPHP 3.2 has many changes based on ThinkPHP 3.1. , I think this version should be set to ThinkPHP 4.0 instead...
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!