A brief talk on thinkphp model _php tutorial

Source: Internet
Author: User

Talking about the thinkphp model of the case


This article mainly introduces several methods of Thinkphp's instantiation model, and the use points between them, very good, recommend to everyone.

The thinkphp instantiation model gives us three ways to

The first is more commonly used

is the $user=new Model (' user '); Also equals $user =m (' user ')

The second is if we have a public model

That's what we use.

For example, we create a model CommonModel.class.php this public

This is what we instantiate.

The code is as follows:


$user =new commonmodel (' user ');

So that we can both instantiate the user model and invoke the method inside the public model

The third is for our instantiation model

Create a model UserModel.class.php

Instantiation is such a $user=new usermodel ();

So that's it, mostly our business logic is more when we use this

Fourth, why would there be a fourth model of emptiness?

The code is as follows:


$user = new Model (); Equivalent to $user=m ();

Then we'll use the SQL statement.

The code is as follows:


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

The use of the D method can automatically detect the model class when it does not exist, throws an exception, does not repeat the instantiation, can only support the current project or the instantiation of the application

Instantiate about that much, and continue to tell you about thinkphp things.

Summarize:

The model definition and instantiation introduced in this paper are biased to the theory, but in the later development, the operation of the data should use the model instantiation, according to the actual situation of the project, we can adopt different model instantiation methods.

http://www.bkjia.com/PHPjc/975900.html www.bkjia.com true http://www.bkjia.com/PHPjc/975900.html techarticle A brief talk on the thinkphp model in the paper this article mainly introduces several methods of thinkphp model, and the use points between them, very good, recommend to everyone. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.