【问题标题】:PHP Front Controller Class Not Found (Namespaces)未找到 PHP 前端控制器类(命名空间)
【发布时间】:2013-03-29 05:26:38
【问题描述】:

以下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 Core\Controller;

class Controller
{

   public function __construct()
   {
       // @TODO
   }
}

索引控制器

namespace Application\Controller;

use Core\Controller\Controller;


class Index extends \Core\Controller\Controller {

    public $input;

    public function __construct() 
    {
        parent::__construct();
        die('In Application Controller');
    }
}

【问题讨论】:

    标签: php oop namespaces front-controller php-include


    【解决方案1】:

    在这一行$ctl = new $controller; $controller 变量必须包含完整路径,包括命名空间

    【讨论】:

      猜你喜欢
      • 2019-03-03
      • 2013-11-11
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      相关资源
      最近更新 更多