Bundles 101

How to get started with

Symfony2 Bundles

Created by Juan Manuel Torres / @onema / onema.io

Let's dive right in


                        $ php app/console generate:bundle
                    

Directory structure and basic routing


# app/config/routing.yml
test:
    resource: "@TestBundle/Resources/config/routing.yml"
    prefix:   /
                    

# src/Onema/TestBundle/Resources/config/routing.yml
# Use a default parameter
test_homepage:
    pattern:  /hello/{name}
    defaults: { _controller: TestBundle:Default:index, name: "Random User" }
                    

Adding a new Route


# src/Onema/TestBundle/Resources/config/routing.yml
test_hello_spanish:
    pattern:  /hola/{name}
    defaults: { _controller: TestBundle:Default:index, name: "Usuario Aleatorio" }
                    

Twig Views


                        src/Onema/Bundle/TestBundle/Resources/views
                    

Installing Bundle Assets


                        src/Onema/Bundle/TestBundle/Resources/public
                    

                        $ php app/console assets:install
                    

THE END

BY Juan Manuel Torres / onema.io / @onema

References

[1]http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_bundle.html [2]http://symfony.com/doc/current/book/routing.html