Frage

The following PHP code

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();
}

Is producing a

Fatal error: Class 'Index' not found in /path/to/core/Dispatch.php on line 108

However, I verified that both the core controller and application controllers are loading.

Controller.php:

namespace Core\Controller;

class Controller
{

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

Index 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');
    }
}
War es hilfreich?

Lösung

In this line $ctl = new $controller; $controller variable must contains full path, including namespaces

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top