


This article mainly introduces the support of multi-layer MVC in the new features of ThinkPHP3.1. It has a certain reference value. Now I share it with you. Friends in need can refer to it
Default The model layer consists of Model classes. However, as the project grows and the business system becomes more complex, it is difficult for a single model layer to meet the requirements. Multi-layer Model support has been launched since 3.1. This article mainly introduces the support of ThinkPHP3.1 multi-layer MVC. Friends who need it can refer to
1. Model (Model) layer: The default model layer is composed of the Model class. However, as the project grows and the business system becomes more complex, it is difficult for a single model layer to meet the requirements. Multi-layer Model support has been launched since 3.1. The design idea is very simple. Different model layers still inherit from the system’s Model class. , but distinctions are made in the directory structure and naming conventions. For example, in a certain project design, it is necessary to distinguish between different model layers such as data layer, logic layer, and service layer. We can create Model, Logic, and Service under the Lib directory of the project. Directory, all model operations on user tables are divided into three layers:
Data layer: Model/UserModel is used to define data-related automatic verification and automatic completion and data access interfaces
Logic layer: Logic/UserLogic is used to define user-related business logic
Service layer: Service/UserService is used to define user-related service interfaces, etc.
These three model operation classes can all inherit the Model class, so that the operation of user data is very clear. When calling, you can also use the built-in D method to conveniently call:
D('User') //实例化UserModel D('User','Logic') //实例化UserLogic D('User','Service') //实例化UserService
The hierarchical division of model layers is very flexible, and developers can freely define hierarchies according to the needs of the project.
2. View layer: is composed of a template and a template engine. PHP code can be used directly in the template. The design of the template engine will be described later, and it can also be supported through the driver. Other third-party template engines. Multiple layers of views can be simply distinguished by directories, for example:
Tpl/default/User/add.html Tpl/blue/User/add.html
##3. Controller layer: ThinkPHP control The controller layer consists of a core controller and a business controller. The core controller is completed by the App class inside the system and is responsible for the scheduling control of applications (including modules and operations), including HTTP request interception and forwarding, loading configuration, etc. The business controller is Completed by user-defined Action class. Version 3.1 has added support for multi-layer service controllers. Its implementation principle is similar to the layering of models, such as business controllers and event controllers:
Action/UserAction //用于用户的业务逻辑控制和调度 Event/UserEvent //用于用户的事件响应操作UserAction is responsible for external interaction responses and responds through URL requests, such as http://serverName/User/index, and UserEvent is responsible for internal event response, and can only be called internally
A('User','Event');, so it is isolated from the outside. The division of multi-layer controllers is not mandatory and can be layered freely according to the needs of the project. In the controller layer, you can call the layered model as needed, or you can call the view templates of different directories.
At the same time, the R method can also support the calling of multi-layer controllers. A third parameter is added to indicate the layer name of the controller, for example:
R('User/register',array(15),'Event');Indicates calling the register method of the UserEvent controller and passing in parameter 15.
In the three layers of MVC,
ThinkPHP does not depend on M or V, and can even only have C or only V. This is The design of ThinkPHP is a very important user experience design. Users only need to define the view, and it can be automatically recognized without C.
A more complete introduction to the new features of ThinkPHP3.1 that support Ajax
About thinkphp to implement password search for sending emails Introduction to the return function
The above is the detailed content of Introduction to the multi-layer MVC support in the new features of ThinkPHP3.1. For more information, please follow other related articles on the PHP Chinese website!

PHP8.3发布:新特性一览随着技术的不断发展和需求的不断变化,编程语言也在不断更新和改进。作为一种广泛应用于网络开发的脚本语言,PHP一直在不断进步,为开发者提供更强大和高效的工具。最近发布的PHP8.3版本带来了许多期待已久的新特性和改进,下面让我们来看一下这些新特性的一览。非空属性的初始化在过去的PHP版本中,如果一个类的属性没有被明确赋值,它的值

深入解析PHP8的新特性,助您掌握最新技术随着时间的推移,PHP编程语言一直在不断演进和改进。最近发布的PHP8版本为开发者提供了许多令人兴奋的新特性和改进,为我们的开发工作带来了更多便利和效率。在本文中,我们将深入解析PHP8的新特性,并提供具体的代码示例,旨在帮助您更好地掌握这些最新的技术。JIT编译器PHP8引入了JIT(Just-In-Time)编

PHP8.1引入的新的Redis扩展随着互联网的快速发展,大量的数据需要进行存储和处理。为了提高数据处理的效率和性能,缓存成为了一个不可或缺的部分。而在PHP开发中,Redis作为一种高性能的键值对存储系统,被广泛应用于缓存和数据存储的场景。为了进一步提升Redis在PHP中的使用体验,PHP8.1引入了新的Redis扩展,本文将介绍这一扩展的新增功能,并给

php8新特性有JIT 编译器、类型推导、命名参数、联合类型、属性、错误处理改进、异步编程支持、新的标准库函数和匿名类的扩展等。详细介绍:1、JIT编译器,PHP8引入了JIT编译器,这是一个重要的性能改进,JIT编译器可以对一些高频执行的代码进行实时编译和优化,从而提高运行速度;2、类型推导,PHP8引入了类型推导功能,允许开发者在声明变量时自动推导出变量的类型等等。

CSS3的新特性一览:如何使用CSS3实现过渡效果CSS3作为CSS的最新版本,在众多新特性中,最有趣和实用的应该是过渡效果(transition)。过渡效果可以让我们的页面在交互时更加平滑、漂亮,给用户带来良好的视觉体验。本文将介绍CSS3过渡效果的基本用法,并附带相应的代码示例。transition-property属性:指定需要过渡的CSS属性过渡效果

go语言的新特性有:1、Go模块,用于管理Go语言项目的依赖关系;2、错误处理,增加了一个新的错误类型error,使得错误处理更加灵活和简洁;3、上下文包,用于在goroutine之间传递请求范围的值;4、嵌入,即一个结构体可以嵌入到另一个结构体中;5、同步包,更好地控制goroutine之间的同步和通信;6、错误值,更好地区分不同类型的错误;7、泛型,让开发者编写更灵活。

CSS3的新特性一览:如何使用CSS3实现水平居中布局在网页设计和布局中,水平居中布局是一项常见的需求。过去,我们经常使用复杂的JavaScript或CSS技巧实现此目的。然而,CSS3引入了一些新的特性,使得水平居中布局更加简单和灵活。本文将介绍一些CSS3的新特性,并提供一些代码示例,演示如何使用CSS3实现水平居中布局。一、使用flexbox布局fle

PHP8作为最新版本的PHP编程语言,引入了许多新的特性和改进,在底层开发原理方面做了一些重要的改变。本文将深入探讨PHP8的底层开发原理,并分析如何利用新特性提高代码性能和可靠性。首先,我们来了解一下PHP8的一些重要的底层开发原理。PHP8引入了JIT(Just-In-Time)编译器,这是一个动态编译器,可以将PHP代码即时转换为本地机器码,并在执行时


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment