composer.json ファイルで psr-4 を使用した方法は次のとおりです
"autoload": {
"psr-4": {"MyMVC\\": "app/"}
},
今、私のinitファイルで、次のようにコントローラーを動的にロードしようとしています
<?php namespace MyMVC;
use MyMVC\Core\Config;
use MyMVC\Controllers;
class Application
{
/**
* Takes the arguments and execute the requested route
*
* @param [type] $controller name of the controller
* @param [type] $method name of method
* @param array $arguments an array of arguments to be passed into method
* @access private
*/
private function dispatch($controller, $method, array $arguments)
{
$controller = 'Controllers\\' . ucfirst($controller) . 'Controller';
$controllerObject = new $controller;
}
私HomeController
の見た目はこんな感じ
<?php namespace MyMVC\Controllers;
class HomeController
{
function __construct()
{
echo 'Hello World';
}
}
URL ` http://localhost/mymvc/home/bla/bla ' にアクセスすると、エラーが発生します
Fatal error: Class 'Controllers\HomeController' not found in /var/www/html/mymvc/app/init.php on line 136