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

Commit 02a3caf

Browse files
committed
Documentation for multiple auto routes feature
1 parent 7aa39e7 commit 02a3caf

File tree

4 files changed

+112
-8
lines changed

4 files changed

+112
-8
lines changed

bundles/routing_auto/definitions.rst

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

5-
RoutingAutoBundle
6-
=================
5+
Introduction
6+
============
77

88
The RoutingAutoBundle allows you to automatically persist routes when
99
documents are persisted based on URI schemas and contextual information.
@@ -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`: http://getcomposer.org/
191196
.. _`symfony-cmf/routing-auto-bundle`: https:/packagist.org/packages/symfony-cmf/routing-auto-bundle

0 commit comments

Comments
 (0)