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:
- I tried
composer dump-autoload -oandcomposer updatewithout luck. - I double checked spelling mistakes in my namespace and folder structure.
- I don't use shorttags eg.
<?
I would appreciate any suggestions from you!