Let's talk about the instantiation model of thinkphp. This article briefly introduces several methods for instantiating thinkphp models and their usage points. it is very good and recommended to you. Thinkphp instantiation model
This article briefly introduces several methods for instantiating the thinkphp model and their usage points. it is very good and is recommended to you.
The thinkphp instantiation model provides three methods.
The first method is more common.
$ User = new Model ('user'); // $ user = M ('user ')
Second, if we have a public model
This is what we use.
For example, we create a model CommonModel. class. php public model.
This is what we instantiate.
The code is as follows:
$ User = new CommonModel ('user ');
In this way, the user model can be instantiated and the methods in the public model can be called.
The third is our instantiation model.
Create a model UserModel. class. php
The instantiation is like this $ user = new UserModel ();
In this way, we can use it when there are many business logic.
Fourth, why is there the fourth null 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. The model class can be automatically detected when the method is used. if the model class does not exist, an exception will be thrown and the model class will not be instantiated repeatedly. it can only be instantiated for the current project or application.
There are so many instantiation cases. let's continue to talk about thinkphp.
Summary:
The model definition and instantiation introduced in this article are biased towards theory. However, in subsequent development, data operations require model instantiation, different model instantiation methods can be adopted based on the actual situation of the project.
This article introduces several methods for instantiating thinkphp models and their usage points. it is very good and recommended to you ....