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 ?