Reputation: 131
I want to create my own bundles in Sylius. I created in the directory src and named App like that
src
Sylius
.......
App
Bundle
ShopBundle
AppShopBundle.php
In this file, I wrote very simple:
namespace App\Bundle\ShopBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AppShopBundle extends Bundle
{
}
And I registered this bundle in AppKernel.php
$bundles = array(
new App\Bundle\ShopBundle\AppShopBundle()
);
But when I run the site, I have an exception. I don't understand the problem here, anyone can help me ?
ClassNotFoundException in AppKernel.php line 28:
Attempted to load class "AppShopBundle" from namespace "App\Bundle\ShopBundle".
Did you forget a "use" statement for "App\Bundle\ShopBundle\AppShopBundle"?
Upvotes: 3
Views: 389
Reputation: 1401
While Tuan's answer will work, it uses psr-0
. Adding an updated answer for psr-4
support.
Change your composer.json's autoload configuration to load the whole source directory like so:
"autoload": {
"psr-4": {
"": "src/"
}
}
Upvotes: 0
Reputation: 73
Tuan's approach worked for me. In my case my composer.json autoload equals:
"autoload": {
"psr-0": { "Sylius\\": "src/", "App\\": "src/" }
},
and then you'll want to clear cache after running 'composer dump-autoload'
php app/console cache:clear --env=dev
Upvotes: 3
Reputation: 570
You should edit composer.json file to autoload your new bundle
"autoload": {
"psr-0": { "": "src/" }
}
Then run composer dump-autoload in terminal
Upvotes: 3