[英]Composer PSR-4 class not found
這是我在composer.json文件中使用psr-4的方法
"autoload": {
"psr-4": {"MyMVC\\": "app/"}
},
現在在我的初始化文件中,我試圖像
<?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
在申請中應
$controller = 'MyMVC\\Controllers\\' . ucfirst($controller) . 'Controller';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.