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

Commit 006cd90

Browse files
committed
explain prefix and simplify book example
1 parent d392bcf commit 006cd90

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

book/routing.rst

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,12 @@ As mentioned above, you can use any route provider. The example in this
440440
section applies if you use the default PHPCR-ODM route provider
441441
(``Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RouteProvider``).
442442

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::
447449

448450
// src/Acme/MainBundle/DataFixtures/PHPCR/LoadRoutingData.php
449451
namespace Acme\DemoBundle\DataFixtures\PHPCR;
@@ -472,7 +474,7 @@ follows::
472474

473475
$route = new Route();
474476
$route->setParentDocument($dm->find(null, '/cms/routes'));
475-
$route->setName('projects');
477+
$route->setName('my-page');
476478

477479
// link a content to the route
478480
$content = new StaticContent();
@@ -483,19 +485,12 @@ follows::
483485
$dm->persist($content);
484486
$route->setContent($content);
485487

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-
492488
$dm->persist($route);
493489
$dm->flush();
494490
}
495491
}
496492

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``.
499494

500495
.. caution::
501496

@@ -506,14 +501,12 @@ also ``/projects`` as there is a default for the id parameter.
506501
something yourself to create the path (by configuring an initializer or
507502
doing it in a fixture like this).
508503

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>`.
515507

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
517510
:ref:`route document section in the RoutingBundle documentation <bundle-routing-document>`.
518511

519512
Further Notes

0 commit comments

Comments
 (0)