Kal
Kal

Reputation: 2299

Composer Autoload - Can't find class

I have a little Silex app going on. Trying to get some sort of structure going on.

This is my composer.json:

{
    "require": {
        "silex/silex": "~1.3"
    },

    "autoload": {
        "psr-0": {
            "HelloWorld\\Controller": "src/HelloWorld/Controllers"
        }
    }
}

In my web/index.php file I have this

$loader = require_once __DIR__.'/../vendor/autoload.php';

$ctrl = new \HelloWorld\Controller\IndexController(); // <- Doesn't work

My IndexController controller in src/HelloWorld/Controllers

namespace HelloWorld\Controller;

class IndexController
{

}

I have tried pretty much every combination under the sun. Anyone know how to register it properly. The Silex stuff loads fine?

FastCGI sent in stderr: "PHP message: PHP Fatal error: Class 'HelloWorld\Controller\IndexController' not found in /srv/http/web/index.php on line 6"

Upvotes: 3

Views: 2940

Answers (1)

Mikel Bitson
Mikel Bitson

Reputation: 3627

I believe the issue is that the autoloader file hasn't been generated so that it knows where to find the class. Try running

composer install

If you'd like to update the components of your website in the future, after the initial install, you can always run composer update to update the repositories.

Upvotes: 2

Related Questions