Slim 3 Class 未找到(控制器)

Slim 3 Class not found (Controller)

我目前正在尝试熟悉 Slim 3,只想添加一个简单的控制器。

错误信息:

Details
Type: Error
Message: Class 'app\controllers\HomeController' not found
File: C:\xampp\htdocs\slim\app\config\dependencies.php
Line: 13

我的项目结构:

\app
   \config
      routes.php
      dependencies.php
   \controllers
      HomeController.php
\public
   index.php
composer.json

composer.json

"autoload": {
    "psr-4" : {
        "App\" : "app/"            
    }
}

dependencies.php

<?php
$container = $app->getContainer();

// controller
$container['HomeController'] = function($container) {
    return new app\controllers\HomeController;
};

routes.php

<?php

$app->get('/', 'HomeController:index');

HomeController.php

<?php

namespace App\Controllers;

class HomeController 
{
    public function index()
    { ... }
}

index.php

<?php    
require __DIR__ . '/../vendor/autoload.php';  
require __DIR__ . '/../app/config/settings.php';
$app = new \Slim\App(["settings" => $config]);    
require __DIR__ . '/../app/config/dependencies.php';    
require __DIR__ . '/../app/config/routes.php'; 
$app->run();

我还尝试了什么:

如果您有任何建议,我将不胜感激!

PHP 的命名空间不区分大小写,Windows 文件系统不区分大小写,但 AFAIK 作曲家的自动加载器不是。尝试:

"autoload": {
    "psr-4" : {
        "app\" : "app/"            
    }
}

不知道这对谁有帮助。所以我们遇到了类似的问题。

我们所做的是删除供应商文件,然后使用 "composer install" 重新安装依赖项。