1. Write your custom model class in the \lib\model of the project directory, naming the method model name Model.class.php first letter (note that there is no point between the model name and mode) This is the thinkphp naming format. If you remove model he will be prompted not to find the models.
2. The class name in the model should be the same as the filename (capitalize the first letter), which is the same as the controller definition, in which the mode class can be inherited and the user-defined model class can be inherited
3. Instantiate the model in the controller, the instantiation model can have a variety of modules such as the mode of instantiating class in PHP $infomode =new new Infomodel (); There is also the instantiation method provided by thinkphp $ $infomode =d (' Info '); The second use of D () is recommended; To instantiate the module, if the D method can automatically detect the model class, the system throws an exception when it does not exist, and the instantiated model is not repeated. The default D method just can support the call to the current project model, if it needs to be called across projects, you need to use: $User = d (' User ', ' Admin '); Instantiate the User Model $user->select () under the Admin project, and if the Module grouping feature is enabled, use: $User = D (' Admin.user ');
Cases:
thinkphp\lib\model\infomodel.class.php
<?php
class Infomodel extends model{public
function test ()
{
phpinfo ();
}
? >
Instantiating in the controller
<?php
//This document is automatically generated for test run
class Indexaction extends Action
{public
Function index ()
{
//$ Test=new Infomodel ();
$test = D (' Info ');
$test->test ();
}
? >