Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit b9035dd

Browse files
committed
Merge pull request #475 from symfony-cmf/cleanup-routing-bundle
reviewed routing documentation
2 parents 707e34c + 90da07e commit b9035dd

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

bundles/routing/dynamic.rst

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ You can configure the route enhancers that decide what controller is used to
1616
handle the request, to avoid hard coding controller names into your route
1717
documents.
1818

19-
The minimum configuration required to load the dynamic router as service
20-
``cmf_routing.dynamic_router`` is to have ``enabled: true`` in your
21-
application configuration, and to specify what route provider to use.
22-
The dynamic router is automatically enabled as soon as you add any other
23-
configuration to the ``dynamic`` entry. When not enabled, the dynamic router
24-
services will not be loaded at all, allowing you to use the ``ChainRouter``
25-
with your own routers.
19+
Configuration
20+
-------------
21+
22+
The minimum configuration required to load the dynamic router is
23+
to specify a route provider backend.
24+
25+
.. note::
26+
27+
When your project is also using the :doc:`CoreBundle <../core/introduction>`,
28+
it is enough to configure persistence on ``cmf_core`` and you do not need to
29+
repeat the configuration for the dynamic router.
2630

2731
.. configuration-block::
2832

@@ -31,17 +35,21 @@ with your own routers.
3135
# app/config/config.yml
3236
cmf_routing:
3337
dynamic:
34-
enabled: true
35-
# route provider configuration...
38+
persistence:
39+
phpcr:
40+
enabled: true
3641
3742
.. code-block:: xml
3843
3944
<!-- app/config/config.xml -->
4045
<?xml version="1.0" encoding="UTF-8" ?>
4146
<container xmlns="http://symfony.com/schema/dic/services">
4247
<config xmlns="http://cmf.symfony.com/schema/dic/routing">
43-
<dynamic enabled="true" />
44-
<!-- route provider configuration... -->
48+
<dynamic>
49+
<persistence>
50+
<phpcr enabled="true" />
51+
</persistence>
52+
</dynamic>
4553
</config>
4654
</container>
4755
@@ -50,15 +58,22 @@ with your own routers.
5058
// app/config/config.php
5159
$container->loadFromExtension('cmf_routing', array(
5260
'dynamic' => array(
53-
'enabled' => true,
54-
// route provider configuration...
61+
'persistence' => array(
62+
'phpcr' => array(
63+
'enabled' => true,
64+
),
65+
),
5566
),
5667
));
5768
69+
When there is no configuration or ``cmf_routing.dynamic.enabled`` is set to
70+
``false``, the dynamic router services will not be loaded at all, allowing
71+
you to use the ``ChainRouter`` with your own routers.
72+
5873
.. _bundle-routing-dynamic-match:
5974

6075
Match Process
61-
~~~~~~~~~~~~~
76+
-------------
6277

6378
Most of the match process is described in the documentation of the
6479
`CMF Routing component`_. The only difference is that this bundle will place
@@ -110,7 +125,7 @@ A custom controller action can look like this::
110125
.. _bundles-routing-dynamic_router-enhancer:
111126

112127
Configuring the Controller for a Route
113-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128+
--------------------------------------
114129

115130
To configure what controller is used for which route, you can configure the
116131
*route enhancers*. Many of them operate on routes implementing
@@ -124,15 +139,15 @@ precedence):
124139
#. (Explicit controller): If there is a ``_controller`` set in
125140
``getRouteDefaults()``, no enhancer will overwrite the controller.
126141
``_template`` will still be inserted if its not already set;
127-
#. Controller by type: requires the route document to return a 'type' value in
142+
#. ``controllers_by_type``: requires the route document to return a 'type' value in
128143
``getRouteDefaults()``. **priority: 60**;
129-
#. Controller by class: requires the route document to be an instance of
144+
#. ``controllers_by_class``: requires the route document to be an instance of
130145
``RouteObjectInterface`` and to return an object for ``getRouteContent()``.
131146
The content document is checked for being ``instanceof`` the class names in
132147
the map and if matched that controller is used. Instanceof is used instead of
133148
direct comparison to work with proxy classes and other extending classes.
134149
**priority: 50**;
135-
#. Template by class: requires the route document to be an instance of
150+
#. ``templates_by_class``: requires the route document to be an instance of
136151
``RouteObjectInterface`` and to return an object for ``getRouteContent()``.
137152
The content document is checked for being ``instanceof`` the class names in
138153
the map and if matched that template will be set as ``'_template'``.
@@ -203,7 +218,7 @@ All routes are located under a configured root path, for example
203218
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
204219

205220
$route = new Route();
206-
$route->setParent($dm->find(null, '/cms/routes'));
221+
$route->setParentDocument($dm->find(null, '/cms/routes'));
207222
$route->setName('projects');
208223

209224
// set explicit controller (both service and Bundle:Name:action syntax work)
@@ -362,8 +377,8 @@ the name indicates, loads ``Route`` entities from an ORM database.
362377

363378
.. caution::
364379

365-
You must install the CoreBundle to utilize this feature if your app
366-
does not have at least DoctrineBundle 1.3 installed.
380+
You must install the CoreBundle to use this feature if your application
381+
does not have at least DoctrineBundle 1.3.0.
367382

368383
.. _bundles-routing-dynamic-generator:
369384

@@ -421,8 +436,9 @@ to generate a route:
421436

422437
.. caution::
423438

424-
It is dangerous to hardcode paths in your templates if the user has a way
425-
to edit and delete them. If the route must exist for sure, it probably
439+
It is dangerous to hardcode paths to PHPCR-ODM documents into your
440+
templates. An admin user could edit or delete them in a way that your
441+
application breaks. If the route must exist for sure, it probably
426442
should be a statically configured route. But route names could come from
427443
code for example.
428444

@@ -451,7 +467,7 @@ object that implements this interface and provides a route for it:
451467

452468
Additionally, the generator also understands the ``content_id`` parameter with
453469
an empty route name and tries to find a content implementing the
454-
``RouteReferrersInterface`` from the configured content repository.
470+
``RouteReferrersInterface`` from the configured content repository:
455471

456472
.. configuration-block::
457473

0 commit comments

Comments
 (0)