Class Not found in AppKernel.php
Solution 1
If you are getting a bundle not found error in Symfony, in composer.json, modify the psr-4
section under autoload
section like this.
"autoload": {
"psr-4": {
"": "src/"
},
},
By doing so, you don't have to explicitly add the new bundle namespaces when you create a new bundle.
Solution 2
Got the same problem. I've just deleted my vendor folder
rm -rf vendor
and relaunch a composer update.. then everything was fine
composer update
Solution 3
If this happened in Symfony 3 (I haven't tested this in symfony 2),
Make sure your bundle is registered in AppKernal.php as:
public function registerBundles() { $bundles = array( ... new YourBundle\YourBundle(), ); ... }
Check if you've updated composer.json
"autoload": { "psr-4": { "AppBundle\\": "src/AppBundle", "YourBundle\\": "src/YourBundle" }, "classmap": [ "app/AppKernel.php", "app/AppCache.php" ] },
Run
composer update
from your console
Solution 4
Had the same problem after adding a bundle with the code generator with Symfony 3.2. I had to add this new bundle in the autoload section of composer.json after the AppBundle :
(...)
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle",
"CoreBundle\\": "src/CoreBundle"
},
(...)
Solution 5
Turns out i needed to add this to the autoloader. Thanks @DevZer0's comment.
$loader->add('Acme', __DIR__ . '/../src');
Jason Lin
Updated on June 12, 2020Comments
-
Jason Lin almost 4 years
I'm trying to deploy my Symfony2 project. When I run the command
php app/console cache:clear --env=prod --no-debug
I get the following error:
PHP Fatal error: Class 'Acme\MainBundle\AcmeMainBundle' not found in /var/www/html/app/AppKernal.php on line 24
This is the in AppKernal.php
public function registerBundles() { $bundles = array( ... new Acme\MainBundle\AcmeMainBundle(), ); ... }
It seems like there's a problem with the namespace?