How to auto generate a bundle in Symfony3?

Ivan Zavadsky

I've tried to automatically generate a bundle in Symfony3, using instructions on the official site: https://symfony.com/doc/current/bundles.html, but failed.

I created a directory \src\TestBundle in my project with a file TestBundle.php in it. I extended my class TestBundle from Bundle and added the use Symfony\Component\HttpKernel\Bundle\Bundle; line before the class declaration.

I added my new bundle name to the bundles list in AppKernel.php.

Finally, when I execute $ php bin/console generate:bundle --namespace=TestBundle, I get this error:

PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TestBundle" from namespace "TestBundle".

Any ideas why that happens?

Alessandro Minoccheri

If you launch this command:

php bin/console generate:bundle --namespace=TestBundle

Symfony create the Bundle for you, you don't need to create file and add It into the AppKernel file.

Try to remove all your files and reference about TestBundle and after launch only the command, Symfony will create and register the Bundle for you.

Instead i you want to create manually thos file you need to create the directory \src\TestBundle and inside It file TestBundle.php. After you need to register It into your AppKernel. After you need to tell to composer to load that bundle, if is not already done use this configuration for autoload inside composer.json

"autoload": {
    "psr-4": {
        "": "src/"
    },
    "classmap": [
        "app/AppKernel.php",
        "app/AppCache.php"
    ]
},

And finally launch the command inside your console:

composer dump-autoload

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to resolve auto generated classes in Symfony3

From Dev

Symfony 2 generate:bundle - with or without namespace /Bundle/

From Dev

How to generate the view files inside the bundle in Symfony2?

From Dev

How to generate the view files inside the bundle in Symfony2?

From Dev

How to generate Absolute URL from Early/Auto loaded Symfony 3 router

From Dev

How to auto generate uuid in cassandra CQL 3 command line

From Dev

How to auto generate IDs in NHibernate

From Dev

How to auto generate web forms?

From Dev

Symfony don't generate new bundle

From Dev

Symfony3 - MISD Phone Number Bundle format

From Dev

Extract the current namespace, bundle, controller and action name symfony3

From Dev

How to generate bundle.js with react and webpack?

From Dev

How to generate bundle.js with react and webpack?

From Dev

Symfony 3: How to create a private bundle

From Dev

Symfony3: How to set multiple connections?

From Dev

How to send parameters in FormType for symfony3?

From Dev

How to generate auto-incrementing ID in R

From Dev

How to auto-generate dependencies for makefile?

From Dev

How to auto-generate methods of the implemented interface

From Dev

JdbcTemplate how to auto generate primary key

From Dev

How does RethinkDB generate auto ids?

From Dev

How to auto-generate getter and setter methods

From Dev

JdbcTemplate how to auto generate primary key

From Dev

How to generate a Auto Increment column for a XML query?

From Dev

Java - How to auto generate input fields?

From Dev

How to auto generate number in ascending form?

From Dev

how to generate crypted password for auto install

From Dev

Error message in terminal when trying to generate bundle in Symfony 2

From Dev

Using knp snappy bundle to generate pdf - symfony2

Related Related

  1. 1

    How to resolve auto generated classes in Symfony3

  2. 2

    Symfony 2 generate:bundle - with or without namespace /Bundle/

  3. 3

    How to generate the view files inside the bundle in Symfony2?

  4. 4

    How to generate the view files inside the bundle in Symfony2?

  5. 5

    How to generate Absolute URL from Early/Auto loaded Symfony 3 router

  6. 6

    How to auto generate uuid in cassandra CQL 3 command line

  7. 7

    How to auto generate IDs in NHibernate

  8. 8

    How to auto generate web forms?

  9. 9

    Symfony don't generate new bundle

  10. 10

    Symfony3 - MISD Phone Number Bundle format

  11. 11

    Extract the current namespace, bundle, controller and action name symfony3

  12. 12

    How to generate bundle.js with react and webpack?

  13. 13

    How to generate bundle.js with react and webpack?

  14. 14

    Symfony 3: How to create a private bundle

  15. 15

    Symfony3: How to set multiple connections?

  16. 16

    How to send parameters in FormType for symfony3?

  17. 17

    How to generate auto-incrementing ID in R

  18. 18

    How to auto-generate dependencies for makefile?

  19. 19

    How to auto-generate methods of the implemented interface

  20. 20

    JdbcTemplate how to auto generate primary key

  21. 21

    How does RethinkDB generate auto ids?

  22. 22

    How to auto-generate getter and setter methods

  23. 23

    JdbcTemplate how to auto generate primary key

  24. 24

    How to generate a Auto Increment column for a XML query?

  25. 25

    Java - How to auto generate input fields?

  26. 26

    How to auto generate number in ascending form?

  27. 27

    how to generate crypted password for auto install

  28. 28

    Error message in terminal when trying to generate bundle in Symfony 2

  29. 29

    Using knp snappy bundle to generate pdf - symfony2

HotTag

Archive