Slim with Controller implementation

Hi,

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)
        	{
        	    var_dump($request);
        	}
        }

then add dependencies.php file

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

Then add router file

$app->post(’/getuser’,‘HomeController:getuser’);

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

Change

namespace src\Controllers;

to:

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 https://github.com/akrabat/slim-bookshelf.

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

Regards,