我遇到过使用 composer 在 Silex 应用程序中加载类的情况。
这个类位于:
src/custom/UserProvider.php
在我的 composer.json 中,我添加了以下行:
"autoload": {
"psr-0": {
"CustomNamespace": "src/custom/"
}
}
在我的 UserProvider.php 文件中,我有:
namespace CustomNamespace;
当我在控制台中运行 composer update 时,这一行被添加到/vendor/composer/autoload_namespaces.php
'CustomNamespace' => $baseDir . '/src/custom/',
但是,当我尝试使用该类时:
new CustomNamespace\UserProvider();
我遇到了这个错误:
Fatal error: Class 'CustomNamespace\UserProvider' not found in /home/ubuntu/www/project/web/index.php on line 27
有人知道这是怎么回事吗?谢谢!
最佳答案
问题正是@Maerlyn 在他的评论中所说的。
当我将文件移动到 src/custom/CustomNamespace/UserProvider.php
时一切正常关于php - Composer 自动加载未在 Silex 中加载类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14928304/