@@ -62,11 +62,12 @@ their configured priority:
62
62
cmf_routing :
63
63
chain :
64
64
routers_by_id :
65
- # enable the DynamicRouter with high priority to allow overwriting
66
- # configured routes with content
67
- cmf_routing.dynamic_router : 200
65
+ # enable the DynamicRouter with a low priority
66
+ # this way the non dynamic routes take precedence
67
+ # to prevent needless database look ups
68
+ cmf_routing.dynamic_router : 20
68
69
69
- # enable the symfony default router with a lower priority
70
+ # enable the symfony default router with a higher priority
70
71
router.default : 100
71
72
72
73
.. code-block :: xml
@@ -78,14 +79,15 @@ their configured priority:
78
79
79
80
<config xmlns =" http://cmf.symfony.com/schema/dic/routing" >
80
81
<chain >
81
- <!-- enable the DynamicRouter with high priority to allow overwriting
82
- configured routes with content -->
82
+ <!-- enable the DynamicRouter with a low priority
83
+ this way the non dynamic routes take precedence
84
+ to prevent needless database look ups -->
83
85
<routers-by-id
84
86
id =" cmf_routing.dynamic_router" >
85
- 200
87
+ 20
86
88
</routers-by-id >
87
89
88
- <!-- enable the symfony default router with a lower priority -->
90
+ <!-- enable the symfony default router with a higher priority -->
89
91
<routers-by-id
90
92
id =" router.default" >
91
93
100
@@ -99,12 +101,13 @@ their configured priority:
99
101
$container->loadFromExtension('cmf_routing', array(
100
102
'chain' => array(
101
103
'routers_by_id' => array(
102
- // enable the DynamicRouter with high priority to allow overwriting
103
- // configured routes with content
104
- 'cmf_routing.dynamic_router' => 200,
104
+ // enable the DynamicRouter with a low priority
105
+ // this way the non dynamic routes take precedence
106
+ // to prevent needless database look ups
107
+ 'cmf_routing.dynamic_router' => 20,
105
108
106
- // enable the symfony default router with a lower priority
107
- 'router.default' => 100,
109
+ // enable the symfony default router with a higher priority
110
+ 'router.default' => 100,
108
111
),
109
112
),
110
113
));
@@ -146,21 +149,23 @@ The Default Symfony2 Router
146
149
---------------------------
147
150
148
151
Although it replaces the default routing mechanism, Symfony CMF Routing allows
149
- you to keep using the existing system. In fact, the default routing is enabled
150
- by default, so you can keep using the routes you declared in your
152
+ you to keep using the existing system. In fact, the standard Symfony2 routing
153
+ is enabled by default, so you can keep using the routes you declared in your
151
154
configuration files, or as declared by other bundles.
152
155
153
156
.. _start-routing-dynamic-router :
154
157
155
158
The DynamicRouter
156
159
-----------------
157
160
158
- This Router can dynamically load Route instances from a given provider. It
159
- then uses a matching process to the incoming request to a specific Route,
160
- which in turn is used to determine which Controller to forward the request to.
161
+ This Router can dynamically load ``Route `` instances from a dynamic source via
162
+ a so called *provider *. In fact it only loads candidate routes. The actual
163
+ matching process is exactly the same as with the standard Symfony2 routing
164
+ mechanism. However the ``DynamicRouter `` additionally is able to determine
165
+ which Controller and Template to use based on the ``Route `` that is matched.
161
166
162
- The bundle's default configuration states that ``DynamicRouter `` is disabled
163
- by default. To activate it, just add the following to your configuration file:
167
+ By default the ``DynamicRouter `` is disabled. To activate it, just add the
168
+ following to your configuration file:
164
169
165
170
.. configuration-block ::
166
171
@@ -194,7 +199,7 @@ by default. To activate it, just add the following to your configuration file:
194
199
));
195
200
196
201
This is the minimum configuration required to load the ``DynamicRouter `` as a
197
- service, thus making it capable of performing any routing. Actually, when you
202
+ service, thus making it capable of performing routing. Actually, when you
198
203
browse the default pages that come with the Symfony CMF SE, it is the
199
204
``DynamicRouter `` that matches your requests with the Controllers and
200
205
Templates.
@@ -205,11 +210,13 @@ Getting the Route Object
205
210
~~~~~~~~~~~~~~~~~~~~~~~~
206
211
207
212
The provider to use can be configured to best suit each implementation's
208
- needs, and must implement the ``RouteProviderInterface ``. As part of this
209
- bundle, an implementation for `PHPCR-ODM `_ is provided. Also, you can easily
210
- create your own, as the Router itself is storage agnostic. The default
211
- provider loads the route at the path in the request and all parent paths to
212
- allow for some of the path segments being parameters.
213
+ needs. As part of this bundle, an implementation for `Doctrine ORM `_ and
214
+ `PHPCR-ODM `_ is provided. Also, you can easily create your own by simply
215
+ implementing the ``RouteProviderInterface ``. Providers are responsible
216
+ for fetching an ordered subset of candidate routes that could match the
217
+ request. For example the default `PHPCR-ODM `_ provider loads the ``Route ``
218
+ at the path in the request and all parent paths to allow for some of the
219
+ path segments being parameters.
213
220
214
221
For more detailed information on this implementation and how you can customize
215
222
or extend it, refer to :doc: `../bundles/routing/introduction `.
@@ -237,23 +244,23 @@ A Route needs to specify which Controller should handle a specific Request.
237
244
The ``DynamicRouter `` uses one of several possible methods to determine it (in
238
245
order of precedence):
239
246
240
- * Explicit: The stored Route document itself can explicitly declare the target
241
- Controller by specifying the '_controller' value in `` getRouteDefaults( ) ``.
242
- * By alias: the Route returns a 'type' value in ``getRouteDefaults( ) ``,
247
+ * Explicit: The `` Route `` document itself can explicitly declare the target
248
+ Controller if one is returned from `` getDefault('_controller' ) ``.
249
+ * By alias: The `` Route `` document returns a value from ``getDefault('type' ) ``,
243
250
which is then matched against the provided configuration from config.yml
244
- * By class: requires the Route instance to implement ``RouteObjectInterface ``
245
- and return an object for ``getRouteContent () ``. The returned class type is
251
+ * By class: Requires the `` Route `` document to implement ``RouteObjectInterface ``
252
+ and return an object for ``getContent () ``. The returned class type is
246
253
then matched against the provided configuration from config.yml.
247
- * Default: if configured, a default Controller will be used.
254
+ * Default: If configured, a default Controller will be used.
248
255
249
256
Apart from this, the ``DynamicRouter `` is also capable of dynamically
250
257
specifying which Template will be used, in a similar way to the one used to
251
258
determine the Controller (in order of precedence):
252
259
253
260
* Explicit: The stored Route document itself can explicitly declare the target
254
- Template in `` getRouteDefaults( ) ``.
255
- * By class: requires the Route instance to implement ``RouteObjectInterface ``
256
- and return an object for ``getRouteContent () ``. The returned class type is
261
+ Template by returning the name of the template via `` getDefaults('_template' ) ``.
262
+ * By class: Requires the Route instance to implement ``RouteObjectInterface ``
263
+ and return an object for ``getContent () ``. The returned class type is
257
264
then matched against the provided configuration from config.yml.
258
265
259
266
Here's an example of how to configure the above mentioned options:
@@ -267,7 +274,7 @@ Here's an example of how to configure the above mentioned options:
267
274
dynamic :
268
275
generic_controller : cmf_content.controller:indexAction
269
276
controllers_by_type :
270
- editablestatic : sandbox_main.controller:indexAction
277
+ editable_static : sandbox_main.controller:indexAction
271
278
controllers_by_class :
272
279
Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent : cmf_content.controller::indexAction
273
280
templates_by_class :
@@ -282,8 +289,8 @@ Here's an example of how to configure the above mentioned options:
282
289
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" >
283
290
284
291
<config xmlns =" http://cmf.symfony.com/schema/dic/routing" >
285
- <dynamic generic-controller =" cmf_content.controllerindexAction " >
286
- <controllers-by-type type =" editablestatic " >
292
+ <dynamic generic-controller =" cmf_content.controller:indexAction " >
293
+ <controllers-by-type type =" editable_static " >
287
294
sandbox_main.controller:indexAction
288
295
</controllers-by-type >
289
296
@@ -308,7 +315,7 @@ Here's an example of how to configure the above mentioned options:
308
315
'dynamic' => array(
309
316
'generic_controller' => 'cmf_content.controller:indexAction',
310
317
'controllers_by_type' => array(
311
- 'editablestatic ' => 'sandbox_main.controller:indexAction',
318
+ 'editable_static ' => 'sandbox_main.controller:indexAction',
312
319
),
313
320
'controllers_by_class' => array(
314
321
'Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent' => 'cmf_content.controller::indexAction',
@@ -338,8 +345,7 @@ Linking a Route with a Model Instance
338
345
Depending on your application's logic, a requested URL may have an associated
339
346
model instance from the database. Those Routes can implement the
340
347
``RouteObjectInterface ``, and optionally return a model instance, that will be
341
- automatically passed to the Controller as the ``$contentDocument `` variable,
342
- if declared as parameter.
348
+ automatically passed to the Controller as the ``contentDocument `` method parameter.
343
349
344
350
Note that a Route can implement the above mentioned interface but still not
345
351
return any model instance, in which case no associated object will be provided.
@@ -367,7 +373,7 @@ configured as follows:
367
373
cmf_routing :
368
374
dynamic :
369
375
controllers_by_class :
370
- Symfony\Cmf\Component\Routing\RedirectRouteInterface : cmf_routing.redirect_controller:redirectAction
376
+ Symfony\Cmf\Component\Routing\RedirectRouteInterface : cmf_routing.redirect_controller:redirectAction
371
377
372
378
.. code-block :: xml
373
379
@@ -464,96 +470,6 @@ in the document.
464
470
For more details, see the
465
471
:ref: `route document section in the RoutingBundle documentation <bundle-routing-document >`.
466
472
467
- Integrating with SonataAdmin
468
- ----------------------------
469
-
470
- If ``sonata-project/doctrine-phpcr-admin-bundle `` is added to the
471
- composer.json require section, the route documents are exposed in the
472
- SonataDoctrinePhpcrAdminBundle. For instructions on how to configure this
473
- Bundle see :doc: `../bundles/doctrine_phpcr_admin `.
474
-
475
- By default, ``use_sonata_admin `` is automatically set based on whether the
476
- SonataDoctrinePhpcrAdminBundle is available but you can explicitly disable it
477
- to not have it even if Sonata is enabled, or explicitly enable to get an error
478
- if Sonata becomes unavailable.
479
-
480
- There are a couple of configuration options for the admin. The
481
- ``content_basepath `` points to the root of your content documents.
482
-
483
- .. configuration-block ::
484
-
485
- .. code-block :: yaml
486
-
487
- # app/config/config.yml
488
- cmf_routing :
489
- dynamic :
490
- persistence :
491
- phpcr :
492
- # use true/false to force using / not using sonata admin
493
- use_sonata_admin : auto
494
-
495
- # used with Sonata Admin to manage content; defaults to cmf_core.content_basepath
496
- content_basepath : ~
497
-
498
- .. code-block :: xml
499
-
500
- <!-- app/config/config.xml -->
501
- <?xml version =" 1.0" encoding =" UTF-8" ?>
502
-
503
- <container xmlns =" http://cmf.symfony.com/schema/dic/services"
504
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" >
505
-
506
- <config xmlns =" http://cmf.symfony.com/schema/dic/routing" >
507
- <dynamic >
508
- <persistence >
509
- <!-- use-sonata-admin: use true/false to force using / not using sonata admin -->
510
- <!-- content-basepath: used with Sonata Admin to manage content;
511
- defaults to cmf_core.content_basepath -->
512
- <phpcr
513
- use-sonata-admin =" auto"
514
- content-basepath =" null"
515
- />
516
- </persistence >
517
- </dynamic >
518
- </config >
519
- </container >
520
-
521
- .. code-block :: php
522
-
523
- // app/config/config.php
524
- $container->loadFromExtension('cmf_routing', array(
525
- 'dynamic' => array(
526
- 'persistence' => array(
527
- 'phpcr' => array(
528
- // use true/false to force using / not using sonata admin
529
- 'use_sonata_admin' => 'auto',
530
-
531
- // used with Sonata Admin to manage content; defaults to cmf_core.content_basepath
532
- 'content_basepath' => null,
533
- ),
534
- ),
535
- ),
536
- ));
537
-
538
- Terms Form Type
539
- ---------------
540
-
541
- The Routing bundle defines a form type that can be used for classical "accept terms"
542
- checkboxes where you place URLs in the label. Simply specify
543
- ``cmf_routing_terms_form_type `` as the form type name and
544
- specify a label and an array with ``content_ids `` in the options::
545
-
546
- $form->add('terms', 'cmf_routing_terms_form_type', array(
547
- 'label' => 'I have seen the <a href="%team%">Team</a> and <a href="%more%">More</a> pages ...',
548
- 'content_ids' => array(
549
- '%team%' => '/cms/content/static/team',
550
- '%more%' => '/cms/content/static/more'
551
- ),
552
- ));
553
-
554
- The form type automatically generates the routes for the specified content and
555
- passes the routes to the trans twig helper for replacement in the label.
556
-
557
473
Further Notes
558
474
-------------
559
475
@@ -564,5 +480,6 @@ For more information on the Routing component of Symfony CMF, please refer to:
564
480
* Symfony2's `Routing `_ component page
565
481
* :doc: `../cookbook/handling_multilang_documents ` for some notes on multilingual routing
566
482
567
- .. _`PHPCR-ODM` : https://github.com/doctrine/phpcr-odm
483
+ .. _`Doctrine ORM` : http://www.doctrine-project.org/projects/orm.html
484
+ .. _`PHPCR-ODM` : http://www.doctrine-project.org/projects/phpcr-odm.html
568
485
.. _`Routing` : http://symfony.com/doc/current/components/routing/introduction.html
0 commit comments