Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Reworded and improved the routing/external_resources article#9102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,19 +4,37 @@ | ||
| How to Include External Routing Resources | ||
| ========================================= | ||
| Simple applications can define all their routes in a single configuration file - | ||
| usually ``app/config/routing.yml`` (see :ref:`routing-creating-routes`). | ||
| However, in most applications it's common to import routes definitions from | ||
| different resources: PHP annotations in controller files, YAML or XML files | ||
| stored in some directory, etc. | ||
| This can be done by importing routing resources from the main routing file: | ||
| .. configuration-block:: | ||
| .. code-block:: yaml | ||
| # app/config/routing.yml | ||
| app_file: | ||
| # loads routes from the given routing file stored in some bundle | ||
| resource: '@AcmeOtherBundle/Resources/config/routing.yml' | ||
| app_annotations: | ||
| # loads routes from the PHP annotations of the controllers found in that directory | ||
| resource: '@AppBundle/Controller/' | ||
| type: annotation | ||
| app_directory: | ||
| # loads routes from the YAML or XML files found in that directory | ||
| resource: '../legacy/routing/' | ||
| type: directory | ||
| app_bundle: | ||
| # loads routes from the YAML or XML files found in some bundle directory | ||
| resource: '@AppBundle/Resources/config/routing/public/' | ||
| type: directory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. just a question. having values of this keys aligned by column is by convention or something? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. yes ... but we only do that for the docs, to improve readability. In code we never align code like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. 👍 | ||
| .. code-block:: xml | ||
| @@ -27,8 +45,17 @@ This can be done by "importing" directories into the routing configuration: | ||
| xsi:schemaLocation="http://symfony.com/schema/routing | ||
| http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
| <!-- loads routes from the given routing file stored in some bundle --> | ||
| <import resource="@AcmeOtherBundle/Resources/config/routing.yml" /> | ||
| <!-- loads routes from the PHP annotations of the controllers found in that directory --> | ||
| <import resource="@AppBundle/Controller/" type="annotation" /> | ||
| <!-- loads routes from the YAML or XML files found in that directory --> | ||
| <import resource="../legacy/routing/" type="directory" /> | ||
| <!-- loads routes from the YAML or XML files found in some bundle directory --> | ||
| <import resource="@AppBundle/Resources/config/routing/public/" type="directory" /> | ||
| </routes> | ||
| .. code-block:: php | ||
| @@ -38,60 +65,26 @@ This can be done by "importing" directories into the routing configuration: | ||
| $collection = new RouteCollection(); | ||
| $collection->addCollection( | ||
| // loads routes from the given routing file stored in some bundle | ||
| $loader->import("@AcmeOtherBundle/Resources/config/routing.yml") | ||
| // loads routes from the PHP annotations of the controllers found in that directory | ||
| $loader->import("@AppBundle/Controller/", "annotation") | ||
| // loads routes from the YAML or XML files found in that directory | ||
| $loader->import("../legacy/routing/", "directory") | ||
| // loads routes from the YAML or XML files found in some bundle directory | ||
| $loader->import("@AppBundle/Resources/config/routing/public/", "directory") | ||
| ); | ||
| return $collection; | ||
| .. note:: | ||
| When importing resources from YAML, the key (e.g. ``app_file``) is meaningless. | ||
| Just be sure that it's unique so no other lines override it. | ||
| Prefixing Imported Routes | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||