简体   繁体   中英

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"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM