前言
ThinkPHP 3.2 基于 ThinkPHP 3.1 的基础上有许多的变化,我觉得这个版本应该设立为 ThinkPHP 4.0 而不是什么 3.2。如果你在使用 ThinkPHP 3.1 请勿贸然迁移升级,这可不是简单的覆盖下文件就安然无恙的事情。
1. PHP 的版本
ThinkPHP 3.2 要求 PHP 5.3 以上的版本,而 ThinkPHP 3.1 只需要 PHP 5.2 就好了
2. 程序文件夹的修改
ThinkPHP 3.2 使用 Application 作为程序文件夹,而 ThinkPHP 3.1 则是用 app 作为程序文件夹。
3. 不同分组设定的升级
建议以后开发尽量不要做分组,要不然针对分组,有不少要处理的地方,这里只是介绍未分组的情况,有做分组的朋友,请上官方文档寻找答案。
ThinkPHP 3.2 设置了一个 Home 目录,很多文件都将迁移到 Home 目录中。
代码如下:
App/Common/common.php => Application/Home/Common/function.php
App/Common/extend.php => Application/Home/Common/extend.php(假设存在定义的话)
App/Conf/Config.php => Application/Home/Conf/config.php
App/Lang/zh-cn/common.php => Application/Home/Lang/zh-cn.php(假设存在的话)
App/Lib/Action => Application/Home/Action
App/Lib/Model => Application/Home/Model
App/Tpl => Application/Home/View
注意,因为 Home 目录的出现,你需要修改你的 .htaccess 文件为
代码如下:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/home/$1 [QSA,PT,L]
否则,将会出现模块找不到的错误。
新的目录对 Action 和 Tpl 进行了重新命名,分别为 Controller 和 View,这样更加直观的体现了 MVC 的文件夹的部署方式。对于那些保留了 Action 的朋友,可以修改 Application/Common/config.php 中的信息:
代码如下:
'DEFAULT_C_LAYER' => 'Action', // 默认的控制器层名称
'MODULE_ALLOW_LIST' => array('Home','Admin',...), // 配置你原来的分组列表
'DEFAULT_MODULE' => 'Home', // 配置你原来的默认分组
4. 系统配置参数的变动
ThinkPHP 3.2 废弃了以下系统配置参数
代码如下:
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
修改了以下配置参数
代码如下:
DEFAULT_MODULE => DEFAULT_CONTROLLER
5. 命名空间
ThinkPHP 3.2 添加了命名空间,把项目的Application/Home/Action目录下面的所有文件,头部添加如下代码(必须是除注释以外的第一行):
代码如下:
namespace Home\Action;
use Think\Action;
如果你的项目使用了控制器分层的话,需要对每个分层的类库文件添加类似的代码,例如有定义Event分层的话,需要在头部添加:
代码如下:
namespace Home\Event;
use Think\Action;
把项目的Application/Home/Model目录下面的所有文件,头部添加如下代码(必须是除注释以为的第一行):
代码如下:
namespace Home\Model;
use Think\Model;
如果你的项目使用了模型分层的话,需要对每个分层的类库文件添加类似的代码,例如如果你有Service分层,需要在头部添加:
代码如下:
namespace Home\Service;
use Think\Model;
6. 方法调整
控制器类Think\Controller或者Think\Action的下列方法已经废除:
废除方法 | 替代方法 |
---|---|
_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. 常量调整
下列常量已经废除:
APP_NAME // 3.2版本中无需再定义该常量
__GROUP__ // 3.2版本中可以用__MODULE__ 表示模块的URL地址
GROUP_NAME //3.2版本中可以用 MODULE_NAME 获取当前模块名
MODE_NAME // 3.2版本中模式扩展已经废弃,参考下面的模式调整部分
这样就基本上完成了迁移,如果中间还有一些修改的话,请上官方文档寻找答案。
以上就是本文所述关于ThinkPHP3.2发生的变化了,希望对大家能够有所帮助。

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software