Home > PHP Framework > ThinkPHP > What are the differences between thinkphp3.2 and 5.0?

What are the differences between thinkphp3.2 and 5.0?

青灯夜游
Release: 2022-02-14 17:41:58
Original
2008 people have browsed it

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.

What are the differences between thinkphp3.2 and 5.0?

The operating environment of this tutorial: Windows 7 system, thinkphp v5.0 version, Dell G3 computer.

The difference between thinkphp5.0 and thinkphp 3.2

5.0There 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):

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 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
    app
  • (definable) instead of the module name; The class name of the controller does not include
  • 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 of the controller;
Database

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 original

M function call can be changed to use the db function, for example: 3.2 version

M('User')->where(['name'=>'thinkphp'])->find();
Copy after login
5.0 version

db('User')->where('name','thinkphp')->find();
Copy after login
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;
  • added Query constructor, query syntax changes;
  • supports closure query;
  • supports block query;
  • supports view query;
  • adds SQL listening events ;
Model

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 contains

Model, 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();
Copy after login
5.0 version

model('User')->where('name','thinkphp')->find();
Copy after login
Main improvements include:

Reconstruct the association model;

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

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

Socket

method and uses SocketLog 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
Copy after login

函数

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template