Home > Article > PHP Framework > The difference between thinkphp5 and 3.2
<img src="https://img.php.cn/upload/article/000/000/020/5d16d4ae8cd5f951.jpg" alt="The difference between thinkphp5 and 3.2" >
thinkphp5.0
version is quite different from the previous version. This article is for users who are familiar with the 3.2
version Some of the main differences of 5.0
are given.
5.0
URL access no longer supports the normal URL
mode, and routing does not support regular routing definitions, but all changes How to cooperate with variable rules (regular definition) for rule routing:
The main improvements are as follows;
Add routing variable rules;
Add combination variable support;
Add resource routing;
Add routing grouping;
Add closure definition support;
Add MISS routing definition;
Support URL routing rule anti-parsing;
5.0
Added request object Request
and response object Response
, Request
unified processing of requests and obtaining request information , The Response
object is responsible for outputting the client or browser response.
The namespace of the controller has been adjusted, and there is no need to inherit any controller class.
app
(definable) instead of the module name; Controller## by default #Suffix, can be configured to enable
use_controller_suffixThe parameter enables the controller class suffix;
method to return data instead of direct output;
attribute to define the preoperation;
Db Class call, the original
M function call can be changed to
db function, for example:
M('User')->where(['name'=>'thinkphp'])->find();
db('User')->where('name','thinkphp')->find();
objects;
objects;
5.0 The model change is the biggest. Basically, the model is a completely object-oriented concept, including associated models. The suffix of the model class no longer carries
Model, but is directly distinguished by the namespace. The original
D The function call is changed to the
model function, and the corresponding model class must be created, for example:
D('User')->where(['name'=>'thinkphp'])->find();
model('User')->where('name','thinkphp')->find();
mechanism;
think\Validate class. Automatic completion is accomplished by defining modifiers in the model.
5.0Zero tolerance for errors, by default an exception will be thrown for any level of error (but 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.
5.0 page
Trace is enhanced to support viewing Trace information in the browser console. The log driver of
5.0 adds the
Socket method and uses
SocketLog to support remote debugging.
5.0The version abandoned most of the original constant definitions, only retaining the framework's path constant definitions, and the rest of the constants can be used
App class or
Request class related attributes or methods to complete, or redefine the required constants yourself.
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_PATHFunction
5.0The core framework does not rely on any custom functions, but still encapsulates some common functions Helper functions, you can redefine or add helper functions at will.
http://www.php.cn/phpkj/thinkphp/
The above is the detailed content of The difference between thinkphp5 and 3.2. For more information, please follow other related articles on the PHP Chinese website!