Home > Backend Development > PHP Tutorial > A brief discussion on the instantiation model of thinkphp_PHP tutorial

A brief discussion on the instantiation model of thinkphp_PHP tutorial

WBOY
Release: 2016-07-13 09:59:26
Original
815 people have browsed it

A brief discussion of thinkphp's instantiation model

This article mainly briefly introduces several methods of thinkphp's instantiation model, as well as the key points of their use. It is very good. Recommended to everyone.

thinkphp instantiation model provides us with three methods

The first type is more commonly used

That’s $user=new Model(‘user’); //It’s also equal to $user=M(‘user’)

The second is if we have a public model

This is how we use it

For example, let’s create a new model CommonModel.class.php, a public model

This is how we instantiate it

The code is as follows:


$user=new CommonModel(‘user’);

In this way we can both instantiate the user model and call methods in the public model

The third one is for our instantiated model

Create a model UserModel.class.php

The instantiation is like this $user=new UserModel();

That’s it. Mainly when we have a lot of business logic, we use it like this

The fourth type Why is there the fourth type of empty model

The code is as follows:


$user= new Model(); //Equivalent to $user=M();

Then let’s use sql statements

The code is as follows:


$list=$user->query(‘select * from wd_user’);

D method can automatically detect the model class when using it. If it does not exist, an exception will be thrown and it will not be instantiated repeatedly. It can only support the instantiation of the current project or application

That’s about all the instantiation, let’s continue to tell you about thinkphp

Summary:

The model definition and instantiation introduced in this article are more theoretical, but in subsequent development, the instantiation of the model will be used for data operations, and different model instantiation methods can be adopted according to the actual situation of the project.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/975900.htmlTechArticleA brief discussion of thinkphp’s instantiation model. This article briefly introduces several methods of thinkphp’s instantiation model. As well as the key points of use between them, it is very good and recommended to everyone. ...
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