Slim with Controller implementation


I just develop an API using slim framework. Implementing controller functionality i got error.

This is the way of am implementing

I just create a folder controllers in src folder

Then add new file HomeController.php with

      namespace src\Controllers;

        class HomeController
        	public function getuser($request,$response,$args)

then add dependencies.php file

$container['HomeController'] = function ($c)
	return new src\Controllers\HomeController;

Then add router file


I got this error

Fatal error: Class ‘App\Controllers\HomeController’ not found in /var/www/html/doothdvlp/api/v1/src/dependencies.php on line 39

Please help me


namespace src\Controllers;


namespace App\Controllers;

I change the namespace to namespace App\Controllers; . Still i got the error

You need to read up on namespaces and how they relate to PSR-4.

Look at how the route, DI factory (in dependencies.php) and the controller interact in

Look composer.json file autoload key:

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

psr-4 indicates translation between namespaces and folders. In this case:

namespace App\Controllers

look inside app/src/controllers folder