[英]Composer PSR-4 class not found
I have a following directory structure 我有以下目录结构
Here is how i used psr-4 in my composer.json file 这是我在composer.json文件中使用psr-4的方法
"autoload": {
"psr-4": {"MyMVC\\": "app/"}
},
Now in my init file i am trying to load the controllers dynamically like 现在在我的初始化文件中,我试图像
<?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;
}
My HomeController
looks like this 我的
HomeController
看起来像这样
<?php namespace MyMVC\Controllers;
class HomeController
{
function __construct()
{
echo 'Hello World';
}
}
Now if i get to the url ` http://localhost/mymvc/home/bla/bla ' I am getting error 现在,如果我进入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
在申请中应
$controller = 'MyMVC\\Controllers\\' . ucfirst($controller) . 'Controller';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.