How to Create a Symfony Bundle

Technically, it is not terribly complicated of a process to manually create a Symfony bundle. I would just need to create the bundle directory structure in the src directory. That’s just four directories and then a few subdirectories. Then I just need to update app/AppKernel.php to load the new bundle. Oh yeah, I would need to create the bundle class in the new bundle src directory. Then all I have to do is add a reference to the routing configuration file I created in my new bundle’s Resources/config directory.

Obviously creating a bundle by hand would be stupid.

To create a bundle, I just run this command in my Symfony root directory.

php app/console generate:bundle --namespace=MikePatton/MrBundle

I don’t have to specify the namespace parameter. When I am creating a bundle, I’m usually creating more than one, so having that parameter on the command-line is easier for me. The aforementioned command would create a bundle called MrBundle in the MikePatton namespace.

Share Button