作曲家自动加载-找不到课程 [英] Composer Autoload - Can't find class
问题描述
我正在运行一个小的Silex应用程序.试图使某种结构继续下去.
I have a little Silex app going on. Trying to get some sort of structure going on.
这是我的composer.json
:
{
"require": {
"silex/silex": "~1.3"
},
"autoload": {
"psr-0": {
"HelloWorld\\Controller": "src/HelloWorld/Controllers"
}
}
}
在我的web/index.php
文件中,我有这个
In my web/index.php
file I have this
$loader = require_once __DIR__.'/../vendor/autoload.php';
$ctrl = new \HelloWorld\Controller\IndexController(); // <- Doesn't work
我在src/HelloWorld/Controllers
namespace HelloWorld\Controller;
class IndexController
{
}
我几乎在阳光下尝试了每种组合.任何人都知道如何正确注册. Silex的东西可以装好吗?
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"
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
如果您以后想更新网站的组件,则在初次安装后,始终可以运行composer update
来更新存储库.
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.
这篇关于作曲家自动加载-找不到课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!