Home >PHP Framework >ThinkPHP >The difference between thinkphp5 and 3.2

The difference between thinkphp5 and 3.2

藏色散人
藏色散人Original
2019-06-29 11:02:403382browse

<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.

URL and routing

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;

Request object and response object

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.

Modules and Controllers

The namespace of the controller has been adjusted, and there is no need to inherit any controller class.

  • The application namespace is unified to app (definable) instead of the module name;
  • The class name of the controller does not contain Controller## by default #Suffix, can be configured to enable use_controller_suffixThe parameter enables the controller class suffix;
  • The controller operation method uses the
  • return method to return data instead of direct output;
  • Abolish the original before and after operation methods;
  • Add
  • beforeActionList attribute to define the preoperation;
  • Support any level of controller definition and access;
  • URL access supports automatic positioning controller;
Database

The database query function of 5.0 has been enhanced. Chain queries that originally needed to be used through the model can be directly used through

Db Class call, the original M function call can be changed to db function, for example:

3.2 version

M(&#39;User&#39;)->where([&#39;name&#39;=>&#39;thinkphp&#39;])->find();

5.0 version

db(&#39;User&#39;)->where(&#39;name&#39;,&#39;thinkphp&#39;)->find();

The main improvements are as follows:

    Supports chain query operations;
  • Data query supports returning objects, arrays and
  • PDOStatement objects;
  • Data set query supports returning arrays and
  • Collection objects;
  • Add query constructor, query syntax changes;
  • Support closure query;
  • Support block query;
  • Support view query;
  • Add SQL listening event;
Model

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:

3.2 version

D(&#39;User&#39;)->where([&#39;name&#39;=>&#39;thinkphp&#39;])->find();

5.0 version

model(&#39;User&#39;)->where(&#39;name&#39;,&#39;thinkphp&#39;)->find();

Main improvements include :

    Reconstruct the association model;
  • Support the aggregation model;
  • Abolish the view model (change to the view query method of the database);
  • The extension of the model adopts the
  • Trait mechanism;
  • Adds getters and modifiers;
  • Adds automatic writing of timestamps;
  • Adds type field conversion;
  • Array access support;
  • JSON serialization support;
Automatic verification and automatic completion

5.0 data automatic verification and automatic completion and Version 3.2 is quite different. Data validation in 5.0 uses validator definition and unified verification through the

think\Validate class. Automatic completion is accomplished by defining modifiers in the model.

Exception

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.

Debugging and logging

5.0 pageTrace 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.

Constant

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 usedApp class or Request class related attributes or methods to complete, or redefine the required constants yourself.

The abolished 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.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.

This article comes from the ThinkPHP framework technical article column:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn