Reputation: 309
I'm currently trying to get familiar with Slim 3 and just want to add a simple controller.
Error message:
Details
Type: Error
Message: Class 'app\controllers\HomeController' not found
File: C:\xampp\htdocs\slim\app\config\dependencies.php
Line: 13
My project structure:
\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();
What I tried else:
composer dump-autoload -o
and composer update
without luck. <?
I would appreciate any suggestions from you!
Upvotes: 2
Views: 4465
Reputation: 1
Don't know who this might help. So we had a similar issue.
What we did was to remove the vendor file and then reinstall the dependencies with "composer install".
Upvotes: 0
Reputation: 36989
PHP's namespaces is case insensitive, Windows file system is case insensitive, but AFAIK composer's autoloader is not. Try with:
"autoload": {
"psr-4" : {
"app\\" : "app/"
}
}
Upvotes: 4