问题
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"
回答1:
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.
来源:https://stackoverflow.com/questions/34044288/composer-autoload-cant-find-class