Composer Autoload - Can't find class

妖精的绣舞 提交于 2019-12-10 18:44:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!