Home Backend Development PHP Tutorial Overview of the overall architecture of thinkPHP5.0 framework [application, module, MVC, driver, behavior, namespace, etc.]

Overview of the overall architecture of thinkPHP5.0 framework [application, module, MVC, driver, behavior, namespace, etc.]

Jun 07, 2018 am 11:52 AM
mvc Namespaces application Architecture module drive

This article mainly introduces the overall architecture of thinkPHP5.0 framework, and briefly introduces the concepts and basic usage of thinkPHP5.0 applications, modules, MVC, drivers, behaviors, namespaces, etc. Friends who need it can refer to it

This article describes the overall architecture of thinkPHP5.0 framework. Share it with everyone for your reference, the details are as follows:

ThinkPHP5.0 applications are organized based on the MVC (Model-View-Controller) method.

MVC is a design pattern that enforces separation of input, processing, and output of an application. Applications using MVC are divided into three core components: model (M), view (V), and controller (C), each of which handles its own tasks.

5.0 URL access is determined by routing. If routing is turned off or there is no matching route, it is based on:

http://serverName/index.php (or other application entry files)/module/controller/operation/parameter/value...

It is necessary to understand some of the following concepts, which may be often mentioned in the following content. and.

Entry file

The PHP file requested by the user is responsible for processing the life cycle of a request (note, not necessarily a URL request). The most common entry file isindex.php, sometimes new entry files are added for some special needs, such as a separate entry file for the background module admin.php or a controller program Entry think all belong to entry files.

Application

Application in ThinkPHP is an object that manages the system architecture and life cycle, and is completed by the system's \think\App class. Applications are usually called and executed in entry files. Applications with the same application directory (APP_PATH) are considered to be the same application, but an application may have multiple entry files.

The application has its own independent configuration file and public (function) file.

Module

A typical application is composed of multiple modules. These modules are usually a subdirectory under the application directory. Each module is independent of itself. configuration files, public files and class library files.

5.0 supports single module architecture design. If there is only one module under your application, then the subdirectory of this module can be omitted and modified in the application configuration file:

1

'app_multi_module' =>  false,

Copy after login

Controller

Each module has an independent MVC class library and configuration file. There are multiple controllers under one module. Respond to requests, and each controller is actually an independent controller class.

The controller is mainly responsible for receiving requests, calling related model processing, and finally outputting it through the view. Strictly speaking, the controller should not be too involved in business logic processing.

In fact, the controller can be skipped in 5.0. Through routing, we can directly dispatch the request to a certain model or other class for processing.

5.0's controller class is more flexible and does not need to inherit any basic class library.

A typical Index controller class is as follows:

1

2

3

4

5

6

7

8

namespace app\index\controller;

class Index

{

  public function index()

  {

    return 'hello,thinkphp!';

  }

}

Copy after login

##Operation

A controller Contains multiple operations (methods), and an operation method is the smallest unit of URL access.

The following is a typical Index controller operation method definition, including two operation methods:

1

2

3

4

5

6

7

8

9

10

11

12

namespace app\index\controller;

class Index

{

  public function index()

  {

    return 'index';

  }

  public function hello($name)

  {

    return 'Hello,'.$name;

  }

}

Copy after login

The operation method can be omitted For any parameter, if a non-optional parameter is defined, the parameter must be passed in through the user request. If it is a URL request, it is usually passed in through $_GET or $_POST.

Model

Model classes usually complete the actual business logic and data encapsulation, and return data independent of the format.

The model class does not necessarily need to access the database, and in the 5.0 architecture design, the database connection will only be made when the actual database query operation is performed, which is a true lazy connection.

ThinkPHP's model layer supports multi-layer design. You can perform more detailed design and division of labor on the model layer, such as dividing the model layer into logical layer/service layer/ Event layer and so on.

View

The data returned after the controller calls the model class is assembled into different formats of output through the view. The view decides to call the template engine to parse the content and then output it or output it directly according to different needs.

Views usually have a series of template files corresponding to different controllers and operation methods, and support dynamically setting the template directory.

Driver

Many components of the system adopt driver design, which can be expanded more flexibly. The location of the driver class is placed under the core class library directory by default. You can also redefine the namespace of the driver class library and change the driver's file location.

Behavior

行为(Behavior)是在预先定义好的一个应用位置执行的一些操作。类似于AOP编程中的“切面”的概念,给某一个切面绑定相关行为就成了一种类AOP编程的思想。所以,行为通常是和某个位置相关,行为的执行时间依赖于绑定到了哪个位置上。

要执行行为,首先要在应用程序中进行行为侦听,例如:

1

2

// 在app_init位置侦听行为

\think\Hook::listen('app_init');

Copy after login

然后对某个位置进行行为绑定:

1

2

// 绑定行为到app_init位置

\think\Hook::add('app_init','\app\index\behavior\Test');

Copy after login

一个位置上如果绑定了多个行为的,按照绑定的顺序依次执行,除非遇到中断。

命名空间

ThinkPHP5采用了PHP的命名空间进行类库文件的设计和规划,并且符合PSR-4的自动加载规范。

相关推荐:

搭建自己的PHP MVC框架

thinkPHP交易详情查询功能

The above is the detailed content of Overview of the overall architecture of thinkPHP5.0 framework [application, module, MVC, driver, behavior, namespace, etc.]. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
Does Logitech ghub driver not support win7? -Why can Logitech ghub driver only be installed on the c drive? Does Logitech ghub driver not support win7? -Why can Logitech ghub driver only be installed on the c drive? Mar 18, 2024 pm 05:37 PM

Does Logitech ghub driver not support win7? Not compatible. Since Windows 7 has stopped updating and is no longer Microsoft's main operating system, many new software no longer supports it, such as Logitech ghub. The main interface of the Logitech driver: 1. The main software interface is on the left. The three buttons are lighting, buttons, and sensitivity settings. 2. In the settings of the lighting interface, the general special effects are relatively conventional, and the audio visual effects are the highlight. They can change color according to the sound frequency, and can be set according to the high, middle and bass bands, with different colors and effects. 3. In button settings, users can edit them here according to their special requirements. 4. In the sensitivity settings, many users will have some of their own settings. They can add the DPI speed switching point by themselves, but

How to Undo Delete from Home Screen in iPhone How to Undo Delete from Home Screen in iPhone Apr 17, 2024 pm 07:37 PM

Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

The role and practical application of arrow symbols in PHP The role and practical application of arrow symbols in PHP Mar 22, 2024 am 11:30 AM

The role and practical application of arrow symbols in PHP In PHP, the arrow symbol (->) is usually used to access the properties and methods of objects. Objects are one of the basic concepts of object-oriented programming (OOP) in PHP. In actual development, arrow symbols play an important role in operating objects. This article will introduce the role and practical application of arrow symbols, and provide specific code examples to help readers better understand. 1. The role of the arrow symbol to access the properties of an object. The arrow symbol can be used to access the properties of an object. When we instantiate a pair

From beginner to proficient: Explore various application scenarios of Linux tee command From beginner to proficient: Explore various application scenarios of Linux tee command Mar 20, 2024 am 10:00 AM

The Linuxtee command is a very useful command line tool that can write output to a file or send output to another command without affecting existing output. In this article, we will explore in depth the various application scenarios of the Linuxtee command, from entry to proficiency. 1. Basic usage First, let’s take a look at the basic usage of the tee command. The syntax of tee command is as follows: tee[OPTION]...[FILE]...This command will read data from standard input and save the data to

What is the architecture and working principle of Spring Data JPA? What is the architecture and working principle of Spring Data JPA? Apr 17, 2024 pm 02:48 PM

SpringDataJPA is based on the JPA architecture and interacts with the database through mapping, ORM and transaction management. Its repository provides CRUD operations, and derived queries simplify database access. Additionally, it uses lazy loading to only retrieve data when necessary, thus improving performance.

How to install win11 driver without digital signature_Tutorial on how to deal with win11 driver without digital signature How to install win11 driver without digital signature_Tutorial on how to deal with win11 driver without digital signature Mar 20, 2024 pm 04:46 PM

Some users have encountered some problems when installing drivers for win11 computers. The computer prompts that the digital signature of this file cannot be verified, resulting in the inability to install the driver. How to solve this problem? Please see the following introduction for details. 1. Press the [Win + [Ctrl+Shift+Enter] Open the Windows Powershell window with administrator rights; 3. User Account Control window, do you want to allow this application to make changes to your device? Click [Yes]; 4. Administrator: Windows Powers

How steep is the learning curve of golang framework architecture? How steep is the learning curve of golang framework architecture? Jun 05, 2024 pm 06:59 PM

The learning curve of the Go framework architecture depends on familiarity with the Go language and back-end development and the complexity of the chosen framework: a good understanding of the basics of the Go language. It helps to have backend development experience. Frameworks that differ in complexity lead to differences in learning curves.

Hand-tearing Llama3 layer 1: Implementing llama3 from scratch Hand-tearing Llama3 layer 1: Implementing llama3 from scratch Jun 01, 2024 pm 05:45 PM

1. Architecture of Llama3 In this series of articles, we implement llama3 from scratch. The overall architecture of Llama3: Picture the model parameters of Llama3: Let's take a look at the actual values ​​of these parameters in the Llama3 model. Picture [1] Context window (context-window) When instantiating the LlaMa class, the variable max_seq_len defines context-window. There are other parameters in the class, but this parameter is most directly related to the transformer model. The max_seq_len here is 8K. Picture [2] Vocabulary-size and AttentionL

See all articles