Symfony 启用自定义包 ClassNotFoundException [英] Symfony enable custom bundle ClassNotFoundException
问题描述
我想安装我自己的包,所以我做了作曲家需要al37350/fftt-bundle":*"
I want to install my own bundle so I did composer require "al37350/fftt-bundle": "*"
然后我在 AppKernel.php 中激活了这个包
Then I activated the bundle in AppKernel.php
new Al\FFTTBundle\AlFFTTBundle(),
但是当我执行 php/bin 控制台时,我遇到了这个错误:
But when I did a php/bin console I have this error :
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "AlFFTTBundle" from namespace "Al\FFTTBundle".
Did you forget a "use" statement for another namespace? in /var/www/yoloFFTT/app/AppKernel.php:19
Stack trace:
#0 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(450): AppKernel->registerBundles()
#1 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(116): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(137): Symfony\Component\HttpKernel\Kernel->boot()
#3 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(124): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands()
#4 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(90): Symfony\Bundle\FrameworkBundle\Console\Application->add(Object(Symfony\Co in /var/www/yoloFFTT/app/AppKernel.php on line 19
bundle 的文件结构:
File structure of bundle :
src
Al
FFTTBundle
AlFFTTBundle.php 的命名空间为 Al\FFTTBundle;
and the namespace of AlFFTTBundle.php is Al\FFTTBundle;
当捆绑包不在供应商目录中时,它可以工作,知道吗?
When the bundle isn't in the vendor directory, it's work, any idea ?
推荐答案
您的 bundle 中的 composer.json 是否包含 psr-0 或 psr-4 自动加载?
Does the composer.json in your bundle contain psr-0 or psr-4 autoloading?
示例:
"autoload": {
"psr-4": {
"Al\\FFTTBundle\\": "src/AlFFTTBundle",
}
}
有关更多信息,请参阅:https://seld.be/notes/psr-4-autoloading-support-in-composer.
For more info see: https://seld.be/notes/psr-4-autoloading-support-in-composer.
这篇关于Symfony 启用自定义包 ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!