Mvc-use the D method to learn thinkPHP. why is calling Common/Model NOT Home/Model? Where do I set it?

Source: Internet
Author: User
Why is it not HomeModel to call CommonModel when thinkPHP uses the D method? Function called externally: {code ...} two types of files: {code ...} {code ...} why is the call of Common/Model instead of Home/Model when thinkPHP uses the D method?

Externally called functions:

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

Two types of files:

This is called: C: \ AppServ \ www \ yb1 \ yangbins \ Common \ Model \ shopModel. class. php
  ()';}}
Why not? C: \ AppServ \ www \ yb1 \ yangbins \ Home \ Model \ shopModel. class. php
  ';}}

Reply content:

Why is the call of Common/Model instead of Home/Model when thinkPHP uses the D method?

Externally called functions:

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

Two types of files:

This is called: C: \ AppServ \ www \ yb1 \ yangbins \ Common \ Model \ shopModel. class. php
  ()';}}
Why not? C: \ AppServ \ www \ yb1 \ yangbins \ Home \ Model \ shopModel. class. php
  ';}}

Using the D method, class is not found according to the path specified by the namespace.
The D method loads the first Class to be found according to the priority, and the sequence starts from comon.

There are two ways to solve your problem.

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

Use command space

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

External call should not be specifieduse 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.