How to Include External Routing Resources

All routes are loaded via a single configuration file - usually app/config/routing.yml
(see Loading Routes). However, if you use routing annotations,
you'll need to point the router to the controllers with the annotations.
This can be done by "importing" directories into the routing configuration:

YAML

1
2
3
4

# app/config/routing.ymlapp:resource:'@AppBundle/Controller/'type:annotation# required to enable the Annotation reader for this resource

XML

1
2
3
4
5
6
7
8
9
10

<!-- app/config/routing.xml --><?xml version="1.0" encoding="UTF-8" ?><routesxmlns="http://symfony.com/schema/routing"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"><!-- the type is required to enable the annotation reader for this resource --><importresource="@AppBundle/Controller/"type="annotation"/></routes>

PHP

1
2
3
4
5
6
7
8
9
10
11

// app/config/routing.phpuseSymfony\Component\Routing\RouteCollection;$collection=newRouteCollection();$collection->addCollection(// second argument is the type, which is required to enable// the annotation reader for this resource$loader->import("@AppBundle/Controller/","annotation"));return$collection;

Note

When importing resources from YAML, the key (e.g. app) is meaningless.
Just be sure that it's unique so no other lines override it.

The resource key loads the given routing resource. In this example the
resource is a directory, where the @AppBundle shortcut syntax resolves
to the full path of the AppBundle. When pointing to a directory, all files
in that directory are parsed and put into the routing.

Note

You can also include other routing configuration files, this is often
used to import the routing of third party bundles: