The search order of the D () method

Source: Internet
Author: User

Using the D () method is more intelligent than using the model class directly, and if the model class is not found in Homemodelusermodel, it will go to the public module to find Commonmodelusermodel. If it is not found, the base class Model () class is instantiated directly, which is equivalent to using the M () method.

It is important to note that the table name in the D (' User ') method needs to be capitalized, because the lookup does not recognize the lowercase user when it jumps into the public module, unless you explicitly write: D (' common/user ') so that the complete notation is done in lowercase User, otherwise if you use D (' User '), it skips the public module directly to instantiate the base class model (). Therefore, it is recommended to form the first letter of the habit, in case of mistakes.

Of course, the above problem is mainly due to the use of lowercase user:

The D (' user ') method can be identified in the Home module, and the direct instantiation is no problem, only occurs when cross-modules (such as common) are asked. Of course, the M (' user ') method can be identified with lowercase.

Also, be aware of using indexed arrays as query criteria:

The D (' User ') method finds the model if there is a manual definition of the data field, then the query will not take effect. It means such a drop:

namespace Homemodel;

Use Thinkmodel;

Class Usermodel extends model{

Protected $fields =array (//This is a manually defined field

' ID ',

' User ',

' _PK ' = ' id ',

' Type ' =>array (

' id ' = ' smallint ',

' User ' = ' varchar '

)

);

// ...

}

At this point, the following code is used under the controller:

$user =d (' user ');

$c [' id ']=2;

$c [' User ']= ' cherry balls ';

Print_r ($user->where ($c)->select ()); Querying using indexed arrays

The results will not be queried unless the manual field is commented out, or the M (' User ') method is used.

The search order of the D () method

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.