Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the instantiation Model of thinkphp

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the use of the instantiated model of thinkphp". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the instantiation model of thinkphp".

The thinkphp instantiation model provides us with three methods.

The first one is more commonly used.

Is $user=new Model ('user'); / / also equals $user=M (' user')

The second is that if we have a common model,

Here's how we use it.

For example, let's build a new common model of model CommonModel.class.php.

That's what we instantiate.

The copy code is as follows:

$user=new CommonModel ('user')

In this way, we can instantiate the user model and call methods in the common model.

The third is the instantiation model for us.

Create a model UserModel.class.php

Instantiation is like this $user=new UserModel ()

This is fine. Mainly, when we have a lot of business logic, we use it like this.

Fourth, why is there a fourth empty model?

The copy code is as follows:

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

Then let's use the SQL statement

The copy code is as follows:

$list=$user- > query ('select * from wd_user')

When the D method is used, the model class can be detected automatically. When it does not exist, an exception will be thrown and will not be repeatedly instantiated. It can only support the instantiation of the current project or application.

That's about all the instantiation. Let's continue to talk about thinkphp.

Summary:

The model definition and instantiation introduced in this paper tend to be theoretical, but in the later development, the operation of the data should use the model instantiation, and different model instantiation methods can be adopted according to the actual situation of the project.

Thank you for your reading, the above is the content of "the use of the instantiation model of thinkphp". After the study of this article, I believe you have a deeper understanding of the use of the instantiation model of thinkphp, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report