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

What are the differences between thinkphp3.2 and 5.0?

青灯夜游
青灯夜游 Original
2022-02-14 17:41:27 1861browse

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 theversion gave some of the main differences in5.0.

URL and routing

##5.0URL access no longer supports the normalURLmode, 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 objectRequestand response objectResponse,Requestuniformly processes requests and obtains request information,ResponseThe 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 thereturn
  • 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 theDb

class. The original

Mfunction call can be changed to use thedbfunction, for example:3.2 version

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

db('User')->where('name','thinkphp')->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 andCollection
  • 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 originalDfunction call is changed to themodelfunction, and The corresponding model class must be created, for example:3.2 version

D('User')->where(['name'=>'thinkphp'])->find();
5.0 version

model('User')->where('name','thinkphp')->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);
  • 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 thethink\Validateclass. 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.0page

Trace

is enhanced to support browser console View Trace information. The log driver of5.0adds the

Socket

method and usesSocketLogto 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

函数

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!

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