RoutingBundle
The RoutingBundle integrates dynamic routing into Symfony using the CMF Routing component . See the component documentation if you are interested in the implementation details of the services explained in this chapter.
The ChainRouter
is meant to replace the default Symfony Router. All it
does is manage a prioritized list of routers and try to match requests and
generate URLs with all of them. One of the routers in that chain can of course
be the default router so you can still use the Symfony standard way of
specifying routes where it makes sense.
Additionally, this bundle delivers useful router implementations. It provides
the DynamicRouter
that routes based on a custom loader logic for Symfony
Route objects. The provider can be implemented using a database. This bundle
provides default implementations for Doctrine PHPCR-ODM and Doctrine ORM.
The DynamicRouter service is only made available when explicitly enabled in the application configuration.
Finally this bundles provides route documents for Doctrine PHPCR-ODM and ORM, as well as a controller for redirection routes.
Installation
You can install this bundle with composer using the symfony-cmf/routing-bundle package.
ChainRouter
The ChainRouter can replace the default Symfony routing system with a chain-
enabled implementation. It does not route anything on its own, but only loops
through all chained routers. To handle standard configured Symfony routes, the
Symfony default router with service name router.default
can be put into
the chain.
You can configure the routing services to use in the chain, see Configuration Reference.
Loading Routers with Tagging
You can use the service tag router
to automatically register your routers.
The tag has an optional priority
attribute. The higher the priority, the
earlier your router will be asked to match the route. If you do not specify the
priority, your router will come last. If there are several routers with the
same priority, the order between them is undetermined. The tagged service
will look like this
1 2 3 4 5 6
# app/config/services.yaml
services:
app.my_router:
class: AppBundle\Routing\MyRouter
tags:
- { name: router, priority: 300 }
See also official Symfony documentation for DependencyInjection tags
Further reading
For more information on Routing in the Symfony CMF, please refer to:
- The configuration reference;
- The documentation of the Dynamic Router;
- Customizing the Dynamic Router;
- The routing component documentation for implementation details of the routers;
- Symfony CMF Sonata Phpcr Admin Integration Bundle;
- Symfony's Routing component documentation.