菜单

The difference between ThinkPHP5.0 version and ThinkPHP3.2 version

2017年11月22日 - PHPer

There is a big difference between the 5 version and the previous version. This article gives some of the main differences between the 5 users who are familiar with version 3.2.

URL and routing

5 of URL access is no longer supported by regular URL patterns, nor does routing support regular routing definitions, but instead of regular routing with variable rules (regular definitions):

The main improvements are as follows:

Increasing routing variable rule; increasing combination variable support; increasing resource routing; increasing routing grouping; increasing closure definition support; increasing MISS routing definition; supporting URL routing rules anti parsing;

Request object and response object

5 adds the request object Request and the response object Response, the Request unified processing request and obtains the request information, the Response object is responsible for the output client or the browser response.

Module and controller

The namespace of the controller is adjusted and can be inherited without any controller class.

The application of app (Unified namespace definition) rather than the module name; controller class name default without the Controller suffix, can open the use_controller_suffix configuration parameter is enabled controller class suffix; operation method of controller with return returns the data rather than direct output; the abolition of the original post method before operation; increase the beforeActionList property before the definition supports arbitrary operation; level controller definition and access; URL access support automatic positioning controller;

data base

5 of the database query function is enhanced, the original chain query that needs to be used by the model can be directly invoked through the Db class. The original M function call can use the DB function, for example:

Version 3.2

M (‘User’) -> where ([‘name’=>’thinkphp’]) -> find ();

Version 5

DB (‘User’) -> where (‘name’,’thinkphp’) -> find ();

The main improvements are as follows:

Support chain query; data query support return objects, arrays and PDOStatement objects; data set and query support returns an array of Collection objects; increase the query builder, query syntax changes; support the closure support block query; query; query support view; increase SQL monitor events;

Model

Model 5 is the biggest change, basically is the concept of object oriented model, including the correlation model, the model class is no longer directly by the suffix Model, namespace distinction, call the D function instead of original model function, and the corresponding model class must be created, for example:

Version 3.2

D (‘User’) -> where ([‘name’=>’thinkphp’]) -> find ();

Version 5

Model (‘User’) -> where (‘name’,’thinkphp’) -> find ();

The main improvements include:

The reconstruction of relevance model; support aggregation model; abolition view model (modified query method for database view); model extended by Trait mechanism; increase access and modify; time stamping automatic writing; increase type field conversion; array access support; JSON sequence support;

Automatic verification and automatic completion

Automatic verification of 5 data and automatically and 3.2 versions differ from the 5 validation data validation using validator definition unified and through the think\Validate class. Automatic completion is done by defining modifiers within the model.

abnormal

5 zero tolerance for errors, default to any level of error thrown exception (but can be set in the application of public error level), and re designed the exception page, showing detailed error information, easy debugging.

Debugging and logging

5 of the page Trace reinforcement, support browser console to view Trace information.

5 log drive adds Socket mode, and SocketLog supports remote debugging.

constant

5 version discarded most of the original definition of the constant, only retain the framework of the path constant definition, the remaining constants can be used App class or Request class related attributes or methods to complete, or redefine the required constants themselves.

The repealed constants include:

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

function

5 version of the core framework does not rely on any custom function, but still encapsulates some of the commonly used functions to the assistant function, you can arbitrarily redefine or add helper functions.

发表评论

电子邮件地址不会被公开。