3

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"?

Celeo
  • 5,017
  • 8
  • 35
  • 39
binbin
  • 123
  • 1
  • 9

3 Answers3

3

You should edit composer.json file to autoload your new bundle

"autoload": {
        "psr-0": { "": "src/" }
}

Then run composer dump-autoload in terminal

Tuan nguyen
  • 554
  • 6
  • 18
3

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
0

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/"
    }
}
harmstyler
  • 1,331
  • 12
  • 20