Book Image

Symfony2 Essentials

Book Image

Symfony2 Essentials

Overview of this book

Table of Contents (17 chapters)
Symfony2 Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Routing


Like with many other frameworks based on the concept of MVC, before any controller is actually executed, Symfony2 needs to know how to handle it. The Symfony routing configuration starts within the app/config/routing_*.yml file. Depending on which environment you fire up, this version of routing is fired up. Usually, this environment file loads the main app/config/routing.yml file, which loads other files from vendors, bundles, and so on. You can, of course, directly define your own single routings here, but it's usually recommended to keep the bundle-specific routings within the bundle itself, while using the main routing only to import resources.

As per the example provided earlier in this chapter, we know our app tries to import another resource file defined as @AppBundle/Resources/config/routing.yml. The @BundleName syntax is a shortcut to the bundle namespace (in our case AppBundle) but namespace can be longer if you include the vendor in your name. Let's take a look at the bundle...