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