Hi all,
I encounter problems fetching a route document by the route name when the route contains dashes.
Summary
The route name of the route /netvlies/routes/about-us
is cmf_routing_dynamic_route_netvlies_routes_about_us
. When generating a path by the route name, the name will be resolved to /netvlies/routes/about/us
.
Full description
Our phpcr repository contains the following route /netvlies/routes/about-us
. When requesting this route (/app_dev.php/about-us
) the route is found within the dynamic router logic and the route name is attached to the request (the _route
key).
The router name (value of key _route
) is cmf_routing_dynamic_route_netvlies_routes_about_us
. The route name is generated in the method findManyByUrl
of class Symfony\Cmf\Bundle\RoutingExtraBundle\Document\RouteRepository
by the following lines of code
$this->routeNamePrefix . preg_replace('/[^a-z0-9A-Z_.]/', '_', $key);
As said above this results in cmf_routing_dynamic_route_netvlies_routes_about_us
.
When I use the router to generate a path by the route:
$this->container->get('router')->generate('cmf_routing_dynamic_route_netvlies_routes_about_us');
This results in an exception:
An exception has been thrown during the rendering of a template ("None of the chained routers were able to generate route "cmf_routing_dynamic_route_netvlies_routes_about_us".")
I found that this is caused by the following lines of code in getRouteByName
of the RouteRepository
class:
$path = str_replace('_', '/', substr($name, strlen($this->routeNamePrefix)));
$route = $this->dm->find($this->className, $path);
In this case the value of $path
will be /netvlies/routes/about/us
. Since there is no route with that path an exception is thrown.
I have tried to add the dash to the preg_replace
so that the route name would be cmf_routing_dynamic_route_netvlies_routes_about-us
but the dash is not allowed by the Symfony Route component.