MVC-Learn thinkphp using the D method, why is calling Common/model not Home/model? Where is it set?

Source: Internet
Author: User
Learn thinkphp using the D method, why is calling Common/model not Home/model?

function for external invocation:

namespace Home\Controller;use Think\Controller;public function model_D(){    $stmt=D('shop');    $stmt->say();}

Two types of files:

被调用的是这个:C:\AppServ\www\yb1\yangbins\Common\Model\shopModel.class.php
  
   ()';    }}
为什么不是这个?C:\AppServ\www\yb1\yangbins\Home\Model\shopModel.class.php
  
   ';    }}

Reply content:

Learn thinkphp using the D method, why is calling Common/model not Home/model?

function for external invocation:

namespace Home\Controller;use Think\Controller;public function model_D(){    $stmt=D('shop');    $stmt->say();}

Two types of files:

被调用的是这个:C:\AppServ\www\yb1\yangbins\Common\Model\shopModel.class.php
  
   ()';    }}
为什么不是这个?C:\AppServ\www\yb1\yangbins\Home\Model\shopModel.class.php
  
   ';    }}

With the D method, the class is not found in the path specified by the namespace.
The D method loads the first found class by priority, and the order is started from Comon.

There are two ways to solve your problem.

$model = D("Home/Shop");

Using the command space

use Home\Model\shopModel;$model = new shopModel();

Should external calls not be specified use Home\Model\shop ?

  • 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.