问题
I want to install my own bundle so I did composer require "al37350/fftt-bundle": "*"
Then I activated the bundle in AppKernel.php
new Al\FFTTBundle\AlFFTTBundle(),
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
File structure of bundle :
src
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 ?
回答1:
Does the composer.json in your bundle contain psr-0 or psr-4 autoloading?
Example:
"autoload": {
"psr-4": {
"Al\\FFTTBundle\\": "src/AlFFTTBundle",
}
}
For more info see: https://seld.be/notes/psr-4-autoloading-support-in-composer.
回答2:
After making this entry in composer.json
"autoload": {
"psr-4": {
"Al\\FFTTBundle\\": "src/AlFFTTBundle",
}
}
run : composer dump-autoload
来源:https://stackoverflow.com/questions/44865694/symfony-enable-custom-bundle-classnotfoundexception