The Bundle System

    In Symfony versions prior to 4.0, it was recommended to organize your ownapplication code using bundles. This is no longer recommended and bundlesshould only be used to share code and features between multiple applications.

    A bundle is similar to a plugin in other software, but even better. The corefeatures of Symfony framework are implemented with bundles (FrameworkBundle,SecurityBundle, DebugBundle, etc.) They are also used to add new features inyour application via third-party bundles.

    Bundles used in your applications must be enabled per in the file:

    In a default Symfony application that uses Symfony Flex,bundles are enabled/disabled automatically for you when installing/removingthem, so you don't need to look at or edit this bundles.php file.

    This section creates and enables a new bundle to show there are only a few steps required.The new bundle is called AcmeTestBundle, where the Acme portion is just adummy name that should be replaced by some "vendor" name that represents you oryour organization (e.g. ABCTestBundle for some company named ABC).

    Start by creating a src/Acme/TestBundle/ directory and adding a new filecalled AcmeTestBundle.php:

    The name AcmeTestBundle follows the standard. You couldalso choose to shorten the name of the bundle to simply TestBundle by namingthis class TestBundle (and naming the file ).

    This empty class is the only piece you need to create the new bundle. Thoughcommonly empty, this class is powerful and can be used to customize the behaviorof the bundle. Now that you've created the bundle, enable it:

    And while it doesn't do anything yet, AcmeTestBundle is now ready to be used.

    • Controller/
    • Contains the controllers of the bundle (e.g. RandomController.php).
    • DependencyInjection/
    • Resources/config/
    • Houses configuration, including routing configuration (e.g. routing.yaml).
    • Holds templates organized by controller name (e.g. Random/index.html.twig).
    • Resources/public/
    • Contains web assets (images, stylesheets, etc) and is copied or symbolicallylinked into the project public/ directory via the assets:install consolecommand.
    • Holds all tests for the bundle.A bundle can be as small or large as the feature it implements. It containsonly the files you need and nothing else.

    As you move through the guides, you'll learn how to persist objects to adatabase, create and validate forms, create translations for your application,write tests and much more. Each of these has their own place and role withinthe bundle.