Home > Backend Development > PHP Tutorial > A brief discussion on the instantiation model of thinkphp, a brief discussion on thinkphp examples_PHP tutorial

A brief discussion on the instantiation model of thinkphp, a brief discussion on thinkphp examples_PHP tutorial

WBOY
Release: 2016-07-13 10:10:13
Original
758 people have browsed it

A brief talk about the instantiation model of thinkphp, a brief talk about thinkphp examples

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 this public model

This is how we instantiate it

Copy code 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

Copy code The code is as follows:

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

Then let’s use sql statements

Copy code 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. Different model instantiation methods can be adopted according to the actual situation of the project.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/937088.htmlTechArticleA brief discussion of thinkphp’s instantiation model, a brief discussion of thinkphp examples thinkphp’s instantiation model provides us with three methods. A more common use is $user=new Model('user'); //It is also equivalent to...
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