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

Commit ffdb43a

Browse files
committed
Merge pull request #743 from symfony-cmf/multi-routing-auto
Revert "Revert "Documentation for multiple auto routes feature""
2 parents 853b25b + 16b7525 commit ffdb43a

File tree

4 files changed

+115
-6
lines changed

4 files changed

+115
-6
lines changed

bundles/routing_auto/definitions.rst

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
.. index::
2+
single: Definitions; RoutingAutoBundle
3+
4+
Multiple Auto Routes
5+
====================
6+
7+
.. versionadded: 2.0
8+
9+
The capability to add multiple routes for a managed object has been
10+
introduced in RoutingAutoBundle 2.0.
11+
12+
In the introduction you were shown an example using a single auto route schema
13+
definition. It is possible to have multiple auto-route definitions for each of your
14+
managed objects, and therefore multiple routes.
15+
16+
Below we will modify the example given in the :doc:`Introduction
17+
<introduction>` and add a
18+
new ``edit`` schema definition which has the ``/admin`` prefix:
19+
20+
.. configuration-block::
21+
22+
.. code-block:: yaml
23+
24+
# src/Acme/ForumBundle/Resources/config/cmf_routing_auto.yml
25+
Acme\ForumBundle\Document\Topic:
26+
definitions:
27+
main:
28+
uri_schema: /my-forum/{category}/{title}
29+
defaults:
30+
type: view
31+
edit:
32+
uri_schema: /admin/my-forum/{category}/{title}
33+
defaults:
34+
type: edit
35+
token_providers:
36+
category: [content_method, { method: getCategoryTitle, slugify: true }]
37+
title: [content_method, { method: getTitle }] # slugify is true by default
38+
39+
.. code-block:: xml
40+
41+
<!-- src/Acme/ForumBundle/Resources/config/cmf_routing_auto.xml -->
42+
<?xml version="1.0" ?>
43+
<auto-mapping xmlns="http://cmf.symfony.com/schema/routing_auto">
44+
<mapping class="Acme\ForumBundle\Document\Topic">
45+
<definition name="main" uri-schema="/my-forum/{category}/{title}">
46+
<default key="type">view</default>
47+
</definition>
48+
49+
<definition name="edit" uri-schema="/admin/my-forum/{category}/{title}">
50+
<default key="type">edit</default>
51+
</definition>
52+
53+
<token-provider token="category" name="content_method">
54+
<option name="method">getCategoryName</option>
55+
<option name="slugify">true</option>
56+
</token-provider>
57+
58+
<token-provider token="title" name="content_method">
59+
<option name="method">getTitle</option>
60+
</token-provider>
61+
</mapping>
62+
</auto-mapping>
63+
64+
Note that we specify the ``defaults``. The ``defaults`` key can be used to
65+
persist key / value information on a route. This information can later be used
66+
for many things, but importantly it can be used by the :doc:`Dynamic Router
67+
<../routing/dynamic>` to determine which controller should be used to handle
68+
the request.
69+
70+
For example, the dynamic router could be configured as follows:
71+
72+
.. configuration-block::
73+
74+
.. code-block:: yaml
75+
76+
# app/config/config.yml
77+
cmf_routing:
78+
# ...
79+
dynamic:
80+
# ...
81+
controllers_by_type:
82+
view: Acme\\BasicCmsBundle\\Controller\\ViewController
83+
edit: Acme\\BasicCmsBundle\\Controller\\ViewController
84+
85+
.. code-block:: xml
86+
87+
<!-- app/config/config.xml -->
88+
<?xml version="1.0" encoding="UTF-8" ?>
89+
<container xmlns="http://symfony.com/schema/dic/services">
90+
<config xmlns="http://cmf.symfony.com/schema/dic/routing">
91+
<! -- ... -->
92+
<dynamic>
93+
<! -- ... -->
94+
<controller-by-type
95+
type="view">
96+
Acme\\BasicCmsBundle\\Controller\\ViewController
97+
</controller-by-type>
98+
<controller-by-type
99+
type="edit">
100+
Acme\\BasicCmsBundle\\Controller\\EditController
101+
</controller-by-type>
102+
</dynamic>
103+
</config>
104+
</container>

bundles/routing_auto/defunct_route_handlers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ can be configured as follows:
9292
<controller-by-type
9393
type="cmf_routing_auto.redirect">
9494
cmf_routing_auto.redirect_controller:redirectAction
95-
</controller-by-class>
95+
</controller-by-type>
9696
</dynamic>
9797
</config>
9898

bundles/routing_auto/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ RoutingAutoBundle
88
token_providers
99
conflict_resolvers
1010
defunct_route_handlers
11-
11+
definitions

bundles/routing_auto/introduction.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ forum topic with the following fictional URI:
9393

9494
- ``https://mywebsite.com/my-forum/drinks/coffee``
9595

96-
The RoutingAutoBundle uses a URI schema to define how routes are generated. A
96+
The RoutingAutoBundle uses a URI schema definitions to define how routes are generated. A
9797
schema for the above URI would look like this (the bundle does not care about
9898
the host or protocol):
9999

@@ -105,7 +105,7 @@ You can see that ``my-forum`` is static (it will not change) but that
105105

106106
The value for tokens are provided by *token providers*.
107107

108-
The schema, token providers, and other configurations (more on this later) are
108+
The schema definitions, token providers, and other configurations (more on this later) are
109109
contained within ``routing_auto.format`` files (currently ``xml`` and ``yaml`` are
110110
supported). These files are contained either in your bundles
111111
``Resources/config`` directory or in a custom location specified in
@@ -120,7 +120,9 @@ document could be defined as follows:
120120
121121
# src/Acme/ForumBundle/Resources/config/cmf_routing_auto.yml
122122
Acme\ForumBundle\Document\Topic:
123-
uri_schema: /my-forum/{category}/{title}
123+
definitions:
124+
main:
125+
uri_schema: /my-forum/{category}/{title}
124126
token_providers:
125127
category: [content_method, { method: getCategoryTitle, slugify: true }]
126128
title: [content_method, { method: getTitle }] # slugify is true by default
@@ -130,7 +132,9 @@ document could be defined as follows:
130132
<!-- src/Acme/ForumBundle/Resources/config/cmf_routing_auto.xml -->
131133
<?xml version="1.0" ?>
132134
<auto-mapping xmlns="http://cmf.symfony.com/schema/routing_auto">
133-
<mapping class="Acme\ForumBundle\Document\Topic" uri-schema="/my-forum/{category}/{title}">
135+
<mapping class="Acme\ForumBundle\Document\Topic">
136+
<definition name="main" uri-schema="/my-forum/{category}/{title}" />
137+
134138
<token-provider token="category" name="content_method">
135139
<option name="method">getCategoryName</option>
136140
<option name="slugify">true</option>
@@ -186,6 +190,7 @@ Read more
186190
* :doc:`token_providers`
187191
* :doc:`conflict_resolvers`
188192
* :doc:`defunct_route_handlers`
193+
* :doc:`definitions`
189194

190195
.. _`with composer`: https://getcomposer.org/
191196
.. _`symfony-cmf/routing-auto-bundle`: https:/packagist.org/packages/symfony-cmf/routing-auto-bundle

0 commit comments

Comments
 (0)