The Symfony CMF Routing component extends the Symfony2 core routing component to allow more flexibility. The most important difference is that the CMF Routing component can load routing information from a database.
This chapter provides background information on the Symfony CMF routing implementation. If you simply want to use routing in the CMF, read the RoutingBundle. If you want to customize how the routing works, please read on in this chapter.
Like the Symfony2 routing component, the CMF routing component does not require the full Symfony2 Framework and can be used in standalone projects as well.
At the core of the Symfony CMF Routing component is the
ChainRouter. The ChainRouter tries to match a request with each
of its registered routers, ignoring the
until all routers got a chance to match. The first match wins - if no router
is thrown. The default Symfony2 router can be added to this chain, so the
standard routing mechanism can still be used in addition to any custom routing.
Additionally, this component provides the DynamicRouter. This router is more configurable and flexible than the Symfony2 core router. It can be configured to load routes from a database, dynamically add information to the routes and also generate URLs from model classes.
The goal of Routing¶
Routing is the task of a framework to determine, based on the web request, what
code it has to call and which parameters to apply. The Symfony2 core
that a router must convert a
an array of routing information. In the full stack Symfony2 framework, the code
to call is defined in the
_controller field of the match parameters. The
framework is going to call the controller specified, matching eventual
parameters of that method by name with the other parameters found in the match
array or in the
Request object attributes field.
For a good introduction to routing in the Symfony2 framework, please read the Routing chapter of the Symfony2 book.
To use this component outside of the Symfony2 framework context, have a look at the core Symfony2 Routing Component to get a fundamental understanding of the component. The CMF Routing Component just extends the basic behaviour.
You can install this component with composer using the
symfony-cmf/routing package. If you are using the
symfony-cmf/routing-bundle you do not need to specify the component
separately, it is required automatically.
As mentioned before, this component was designed to use independently of the Symfony2 framework. However, if you wish to use it as part of your Symfony CMF project, an integration bundle is also available. Read more about the RoutingBundle in RoutingBundle in the bundles documentation.
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.