mvc - When learning thinkPHP and using the D method, why is Common/Model called instead of Home/Model? Where is it set?

WBOY
Release: 2016-07-06 13:54:09
Original
1008 people have browsed it

Learn thinkPHP and use D method, why call Common/Model instead of Home/Model?

Externally called function:

<code>namespace Home\Controller;
use Think\Controller;

public function model_D()
{
    $stmt=D('shop');
    $stmt->say();
}</code>
Copy after login
Copy after login

Two types of files:

<code>被调用的是这个:
C:\AppServ\www\yb1\yangbins\Common\Model\shopModel.class.php
<?php
namespace Common\Model;
use Think\Model;

class shopModel extends Model
{
    function say()
    {
        echo 'i am in namespace Common\Model <br>()';
    }
}
</code>
Copy after login
Copy after login
<code>为什么不是这个?
C:\AppServ\www\yb1\yangbins\Home\Model\shopModel.class.php
<?php
namespace Home\Model;
use Think\Model;

class shopModel extends Model
{
    function say()
    {
        echo 'i am in namespace Home\Model <br>';
    }
}</code>
Copy after login
Copy after login

Reply content:

Learn thinkPHP and use D method, why call Common/Model instead of Home/Model?

Externally called function:

<code>namespace Home\Controller;
use Think\Controller;

public function model_D()
{
    $stmt=D('shop');
    $stmt->say();
}</code>
Copy after login
Copy after login

Two types of files:

<code>被调用的是这个:
C:\AppServ\www\yb1\yangbins\Common\Model\shopModel.class.php
<?php
namespace Common\Model;
use Think\Model;

class shopModel extends Model
{
    function say()
    {
        echo 'i am in namespace Common\Model <br>()';
    }
}
</code>
Copy after login
Copy after login
<code>为什么不是这个?
C:\AppServ\www\yb1\yangbins\Home\Model\shopModel.class.php
<?php
namespace Home\Model;
use Think\Model;

class shopModel extends Model
{
    function say()
    {
        echo 'i am in namespace Home\Model <br>';
    }
}</code>
Copy after login
Copy after login

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

There are two ways to solve your problem.

<code>$model = D("Home/Shop");</code>
Copy after login

Use command space

<code>use Home\Model\shopModel;
$model = new shopModel();</code>
Copy after login

Shouldn’t external calls specify use HomeModelshop?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!