Thinkphp introduces custom model ____php

Source: Internet
Author: User

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 ();
    }
? >


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.