thinkphp Study notes (vi) Four ways to instantiate a model

Source: Internet
Author: User
thinkphp Study notes (vi) Four ways to instantiate a model


This article is based on the thinkphp study Note (v) to modify, if a classmate use this code, please read the thinkphp study notes first (v)

Create an Action class

 Select ();//dump ($list);////Two: cross-model operations; Instantiate a table and instantiate a database operation class of its own write//More used to draw out some common business logic to form a common model////m (' user ', ' Commonmodel ') is equivalent to new Commonmodel (' user '), model is automatically loaded////$user =m (' user ', ' Commonmodel ');//$user =new Commonmodel (' User ');//$list = $user->select ();//dump ($list);//$user->modeltest ();//Three: Instantiate a user-defined model//More for a business//1 that does not require more complexity. Create a model manually, create a custom model for the user table, and encapsulate the functionality provided by thinkphp//$user =new Usermodel () equivalent to D (' user '),//d method if the model does not exist, throws an exception, only instance one, default, Only support calls to the following model//$user =new Usermodel ();//$list = $user->select ();//dump ($list);//$user->modeltest ();//Iv. Instantiate an empty model, that is, the traditional way of SQL statements, need to add a table prefix//$user =new Model (), $list = $user->query (' select * from Tb_user ');d UMP ($list);//Group: D ( ' Admin.user ');}? >

Two models:

 
  

 
  


  • 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.