Q:

Custom url generator class

I am looking for a way to override the generation of the url for a specific route in Symfony2.
In symfony 1.4 I used to do it like this:
RouteName:
  class: sfDoctrineRouteCollection
  options:
    model:                Model
    prefix_path:          /route/:id/:slug
    column:               id
    route_class:          CustomDoctrineRoute

class CustomDoctrineRoute extends sfDoctrineRoute
{
  public function generate($params, $context = array(), $absolute = false)
  {
    //custom logic on route params

    return parent::generate($params, $context, $absolute);
  }

}

A:

You can overwrite core Router class path:
<parameters>
    <parameter key="router.class">Company\Bundle\Router\CustomRouter</parameter>
</parameters>

Default Router class (Symfony\Bundle\FrameworkBundle\Routing\Router) have default options (see method setOptions()), you can set them in your app parameters and overwrite needed class, instead all Router:
router.options.generator_class:  Company\Bundle\Router\UrlGenerator

I hope this will solve your problem.

