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 in 5.0
.
URL and routing
##5.0 URL access no longer supports the normal
URL mode, 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.0 Added request object Request
and response object Response
, 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 include The 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 the Db
class. The originalM function call can be changed to use the
db function, for example:
3.2 version
M('User')->where(['name'=>'thinkphp'])->find();
db('User')->where('name','thinkphp')->find();
Supports chain query operations;
Data set query supports returning arrays and
Collection added 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
D function call is changed to the
model function, and The corresponding model class must be created, for example:
3.2 version
D('User')->where(['name'=>'thinkphp'])->find();
model('User')->where('name','thinkphp')->find();
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 the think\Validate class. 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.0 page
Trace is enhanced to support browser console View Trace information. The log driver of 5.0
adds the
method and uses SocketLog
to support remote debugging. constant
废除的常量包括: 函数 【相关教程推荐:thinkphp框架】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
版本核心框架不依赖任何自定义函数,但仍然封装了一些常用功能到助手函数,你可以随意重新定义或者增加助手函数。
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!