Thinkphp Getting Started five-model (49)

Source: Internet
Author: User

"Database Operations Model models"

Model Database Operations

TP Framework Main design pattern: MVC

C:controller Controller shop/lib/action/Specific controller

V:view view shop/tpl/grouping/template files

M:model Data Model shop/lib/model/Concrete model

"Create Model"

Principle of Creation: a data table corresponding to a data model

To create a model:

When the following information appears, our database does not have a user name and password configured config.php

"Database Use steps":
    1. Create model file shop/lib/model/goodsmodel.class.php
    2. Set the database name, user name, password, and table pre-information in the config.php
    3. Goodsmodel model objects can be instantiated directly inside the controller
"Database Configuration config.php": "Get related information from database-query"

We use the Select () method to obtain data information from the database, which returns a two-dimensional array,

If we want to get a record, we use the Find () method, which returns a one-dimensional array

$goods Select ()//Get all records, all field results

$goods, select (15)//Get record results for primary key equals 15

$goods Select ("10,15,20")//Get the primary key record information in the range 10, 15, 20

$goods, find (16); Give us a one-dimensional array to return the record information with the primary key equal to 16

$goods-getbyxxx (); According to the specific XXX field to do the Where condition query, one-dimensional array results returned. This method will take the __call () automatic condition method inside the Model.class.php.

"Capitalization problem": "Get data concrete presentation through model models": "Instantiating model Mode"
    1. The traditional way new Goodsmodel () can
    2. You can instantiate a model object with the shortcut function D ()

For example: D (' Goods '); Instantiating goods Model objects

D (); Instantiates a base class object that needs to specify the data table name when it is used

and primary key names, more complex, not recommended for direct use

3 instantiating a base class object by using the shortcut function m ()

For example: M () instantiates the Model.class.php corresponding object, which is not recommended for use

"To create a model, it is possible that the corresponding table prefix of this model is inconsistent with the other table prefixes, then the model needs to define its own real table name":?

Thinkphp Getting Started five-model (49)

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.