Home>Article>PHP Framework> What are the differences between thinkphp3.2 and 5.0?
Differences: 1. 3.2 supports ordinary URL patterns and regular routing definitions, but 5.0 does not support it; 2. 5.0 adds request object Request and response object Response; 3. 5.0 has zero tolerance for errors, but 3.2 does not; Version 4. 5.0 abandoned most of the original constant definitions and only retained the framework’s path constant definitions.
The operating environment of this tutorial: Windows 7 system, thinkphp v5.0 version, Dell G3 computer.
5.0
There is a big difference between the version and the previous version. This article is familiar with3.2 Users of the
version gave some of the main differences in5.0
.
URL and routing
##5.0URL access no longer supports the normal
URLmode, Routing also does not support regular routing definitions, but all are changed to rule routing with variable rules (regular definitions):
Request object and response object
# #5.0Added request objectRequest
and response objectResponse
,Request
uniformly processes requests and obtains request information,Response
The object is responsible for outputting client or browser responses.
Modules and ControllersThe namespace of the controller has been adjusted, and there is no need to inherit any controller class.
The application namespace is unified to
The class name of the controller does not includeThe parameter enables the controller class suffix;
The controller operation method uses the
returnAbolish the original before and after operation methods;
Support any level of controller definition and access;
5.0’s database query function has been enhanced, which originally required a model. The chain query used can be called directly through theDb
class. The originalMfunction call can be changed to use the
dbfunction, for example:
3.2 version
M('User')->where(['name'=>'thinkphp'])->find();5.0 version
db('User')->where('name','thinkphp')->find();The main improvements are as follows:
Supports chain query operations;
Data set query supports returning arrays and
Collectionadded Query constructor, query syntax changes;
5.0
has the biggest model change. Basically, the model is completely object-oriented. concept, including associated models. The suffix of the model class no longer containsModel, but is directly distinguished by the namespace. The original
Dfunction call is changed to the
modelfunction, and The corresponding model class must be created, for example:
3.2 version
D('User')->where(['name'=>'thinkphp'])->find();5.0 version
model('User')->where('name','thinkphp')->find();Main improvements include:
Reconstruct the association model;
Adds getters and modifiers;
## The automatic data verification and automatic completion of #5.0 are quite different from the 3.2 version. The data verification of 5.0 adopts the validator definition and performs unified verification through thethink\Validateclass. Automatic completion is accomplished by defining modifiers in the model.
Exceptions
5.0Zero tolerance for errors, by default an exception will be thrown for any level of error ( However, the error level can be set in the application public file), and the exception page has been redesigned to display detailed error information for easy debugging.
Debugging and logging
5.0page
Traceis enhanced to support browser console View Trace information. The log driver of5.0
adds the
method and usesSocketLog
to support remote debugging.constant
5.0
版本废弃了原来的大部分常量定义,仅仅保留了框架的路径常量定义,其余的常量可以使用App
类或者Request
类的相关属性或者方法来完成,或者自己重新定义需要的常量。
废除的常量包括:
REQUEST_METHOD IS_GET IS_POST IS_PUT IS_DELETE IS_AJAX __EXT__ COMMON_MODULE MODULE_NAME CONTROLLER_NAME ACTION_NAME APP_NAMESPACE APP_DEBUG MODULE_PATH
函数
5.0
版本核心框架不依赖任何自定义函数,但仍然封装了一些常用功能到助手函数,你可以随意重新定义或者增加助手函数。
【相关教程推荐:thinkphp框架】
The above is the detailed content of What are the differences between thinkphp3.2 and 5.0?. For more information, please follow other related articles on the PHP Chinese website!