|
| 1 | +.. index:: |
| 2 | + single: Routing; Extra Information |
| 3 | + |
| 4 | +Looking up Routes from a Database: Symfony CMF DynamicRouter |
| 5 | +============================================================ |
| 6 | + |
| 7 | +The core Symfony Routing System is excellent at handling complex sets |
| 8 | +of routes. A highly optimized routing cache is dumped during |
| 9 | +deployments. |
| 10 | + |
| 11 | +However, when working with large amounts of data that each need a nice |
| 12 | +readable URL (e.g. for search engine optimization purposes), the routing |
| 13 | +can get slowed down. Additionally, if routes need to be edited by users, |
| 14 | +the route cache would need to be rebuilt frequently. |
| 15 | + |
| 16 | +For these cases, the ``DynamicRouter`` offers an alternative approach: |
| 17 | + |
| 18 | +* Routes are stored in a database; |
| 19 | +* There is a database index on the path field, the lookup scales to huge |
| 20 | + numbers of different routes; |
| 21 | +* Writes only affect the index of the database, which is very efficient. |
| 22 | + |
| 23 | +When all routes are known during deploy time and the number is not too |
| 24 | +high, using a :doc:`custom route loader <custom_route_loader>` is the |
| 25 | +preferred way to add more routes. When working with just one type of |
| 26 | +objects, a slug parameter on the object and the ``@ParamConverter`` |
| 27 | +annotation work fine (see FrameworkExtraBundle_) . |
| 28 | + |
| 29 | +The ``DynamicRouter`` is useful when you need ``Route`` objects with |
| 30 | +the full feature set of Symfony. Each route can define a specific |
| 31 | +controller so you can decouple the URL structure from your application |
| 32 | +logic. |
| 33 | + |
| 34 | +The DynamicRouter comes with built-in support for Doctrine ORM and Doctrine |
| 35 | +PHPCR-ODM but offers the ``ContentRepositoryInterface`` to write a custom |
| 36 | +loader, e.g. for another database type or a REST API or anything else. |
| 37 | + |
| 38 | +The DynamicRouter is explained in the `Symfony CMF documentation`_. |
| 39 | + |
| 40 | +.. _FrameworkExtraBundle: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html |
| 41 | +.. _`Symfony CMF documentation`: http://symfony.com/doc/master/cmf/book/routing.html |
0 commit comments