以下 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 和应用程序 Controller 都在加载。
Controller .php:
namespace Core\Controller;
class Controller
{
public function __construct()
{
// @TODO
}
}
索引 Controller
namespace Application\Controller;
use Core\Controller\Controller;
class Index extends \Core\Controller\Controller {
public $input;
public function __construct()
{
parent::__construct();
die('In Application Controller');
}
}
最佳答案
在这一行 $ctl = new $controller;
$controller 变量必须包含完整路径,包括命名空间
关于未找到 PHP 前端 Controller 类(命名空间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15697841/