@@ -440,10 +440,12 @@ As mentioned above, you can use any route provider. The example in this
440
440
section applies if you use the default PHPCR-ODM route provider
441
441
(``Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RouteProvider ``).
442
442
443
- All routes are located under the base path configured in the application
444
- configuration ``cmf_routing.persistence.phpcr.route_basepath ``. By default
445
- this path is ``/cms/routes ``. A new route can be created in PHP code as
446
- follows::
443
+ PHPCR-ODM documents are stored in a tree, and their ID is the path in that
444
+ tree. To match routes, a part of the repository path is used as URL. To avoid
445
+ mixing routes and other documents, routes are placed under a common root path
446
+ and that path is removed from the ID to build the URL. The common root path is
447
+ called "route basepath". The default base path is ``/cms/routes ``. A new route
448
+ can be created in PHP code as follows::
447
449
448
450
// src/Acme/MainBundle/DataFixtures/PHPCR/LoadRoutingData.php
449
451
namespace Acme\DemoBundle\DataFixtures\PHPCR;
@@ -472,7 +474,7 @@ follows::
472
474
473
475
$route = new Route();
474
476
$route->setParentDocument($dm->find(null, '/cms/routes'));
475
- $route->setName('projects ');
477
+ $route->setName('my-page ');
476
478
477
479
// link a content to the route
478
480
$content = new StaticContent();
@@ -483,19 +485,12 @@ follows::
483
485
$dm->persist($content);
484
486
$route->setContent($content);
485
487
486
- // now define an id parameter; do not forget the leading slash if you
487
- // want /projects/{id} and not /projects{id}
488
- $route->setVariablePattern('/{id}');
489
- $route->setRequirement('id', '\d+');
490
- $route->setDefault('id', 1);
491
-
492
488
$dm->persist($route);
493
489
$dm->flush();
494
490
}
495
491
}
496
492
497
- This will give you a document that matches the URL ``/projects/<number> `` but
498
- also ``/projects `` as there is a default for the id parameter.
493
+ Now the CMF will be able to handle requests for the URL ``/my-content ``.
499
494
500
495
.. caution ::
501
496
@@ -506,14 +501,12 @@ also ``/projects`` as there is a default for the id parameter.
506
501
something yourself to create the path (by configuring an initializer or
507
502
doing it in a fixture like this).
508
503
509
- Because you defined the ``{id} `` route parameter, your controller can expect an
510
- ``$id `` parameter. Additionally, because you called ``setContent `` on the
511
- route, your controller can expect the ``$contentDocument `` parameter.
512
- The content could be used to define an intro section that is the same for each
513
- project or other shared data. If you don't need content, you can just not set it
514
- in the document.
504
+ Because you called ``setContent `` on the route, the controller can expect the
505
+ ``$contentDocument `` parameter. You can now configure which controller should
506
+ handle ``StaticContent `` as :ref: `explained above <start-routing-getting-controller-template >`.
515
507
516
- For more details, see the
508
+ The PHPCR-ODM routes support more things, for example route parameters,
509
+ requirements and defaults. This is explained in the
517
510
:ref: `route document section in the RoutingBundle documentation <bundle-routing-document >`.
518
511
519
512
Further Notes
0 commit comments