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
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
Then let’s use sql statements
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.