使用的是ThinkPHP3.2.2,发现命名空间出现问题,无法使用!
#/Application/Common/Common/Api/WebServer.php
namespace Common\Api;
class WebServer {
public function demo(){
var_dump( __NAMESPACE__ );
var_dump( __FILE__ , __LINE__ );
}
}
#/Application/Home/Controller/InitController.class.php
namespace Home\Controller;
use Think\Controller;
use Common\Api;
class IndexController extend Controller {
public function index(){
//引入了 /Application/Common/Common/Api/WebServer.php
load('Common.Api.WebServer');
}
}
#/Application/Home/Controller/IndexController.class.php
namespace Home\Controller;
class IndexController extend InitController {
public function index(){
$demo = new WebServer();
var_dump( $demo->demo() );
}
}
#访问 HomeController 控制器的 index模块报错提示:
Class 'Home\Controller\WebServer' not found
ringa_lee2017-04-10 14:56:11
<?php
#/Application/Home/Controller/IndexController.class.php
use \Common\Api; 然后 new WebServer();
#或者
new \Common\Api\WebServer();