以下PHP代码
public function go()
{
$controller = ucfirst($this->getController());
$method = $this->getAction();
require_once VENDOR_PATH . DS . 'Core/Controller/Controller.php';
require_once VENDOR_PATH . DS . 'Application/Controller/' . $controller . '.php';
$ctl = new $controller;
$ctl->$method();
}
正在生成
Fatal error: Class 'Index' not found in /path/to/core/Dispatch.php on line 108
但是,我验证了核心控制器和应用控制器都在加载。
Controller.php:
namespace CoreController;
class Controller
{
public function __construct()
{
// @TODO
}
}
指数控制器
namespace ApplicationController;
use CoreControllerController;
class Index extends CoreControllerController {
public $input;
public function __construct()
{
parent::__construct();
die('In Application Controller');
}
}
$ctl = new $controller;
$controller变量必须包含完整路径,包括命名空间