search
HomePHP FrameworkThinkPHPThe difference between thinkphp m and d

The difference between thinkphp m and d

Jun 13, 2019 am 09:09 AM
phpthinkphp

The difference between thinkphp m and d

In the process of instantiation, D method and M method are often used. The difference between these two methods is that the M method instantiates the model without the user defining a model class for each data table. If the D method does not find the defined model class, the M method is automatically called. In layman's terms: the M instantiation parameter is the table name of the database. D instantiates the model file you created under the Model folder

例如:$user = new UserModel();
等价于$user = D('user');
如果实例化的是一个空模型
例如 $Demo = new Model();
那么它等价于 $Demo = M();

The main difference between D and M is : The M method does not require the creation of a model class File, the M method does not read the model class, so automatic verification is invalid by default, but it can be achieved through dynamic assignment and the D method must create the model class. We can use the following two methods to create a mapping object of a data table. The first is: $Test = D('Test') The second is: $Test = new Model('Test'). Although both of these can map data Performing select, insert, delete, and udpate operations is very different in data verification. Using the first method to instantiate a model will have a data checking function. If the title is not filled in, it will prompt "Please enter the title" (this It is an automatic verification function provided by tp. Of course, the verification conditions need to be defined in the corresponding model); if you use the second type, it will not be available... There is another difference. When $trueTableName is used, it must Using $test=d('test') means that the query is the test table. If $test=m('test') is used, it means that the data side of the query is think_test. The thinkphp2.0 version test has the above problem

In layman's terms: D is to instantiate a Model based on the Model file. M dynamically instantiates a Model object by directly instantiating the Model method (ThinkPHP base class), even if the corresponding Model file does not exist

A quickly instantiates the Action class library B executes the behavior class C configuration Parameter access method D Fast instantiation of Model class library F Fast and simple text data access method L Language parameter access method M Fast high-performance instantiation model R Fast remote call Action class method S Fast cache access method U URL dynamic generation and Redirection method W and fast Widget output method D function instantiate the module under Lib/Model of your current project. If the module does not exist, the object of the instantiated Model is directly returned (the meaning is the same as the M() function). And M only returns the object that instantiates the Model. Its $name parameter is used as the table name of the database to handle operations on the database.

For more ThinkPHP related technical articles, please visit the ThinkPHP usage tutorial column to learn!

The above is the detailed content of The difference between thinkphp m and d. 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

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

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

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.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.