schmittjoh / JMSI18nRoutingBundle

Allows you to internationalize your routing
http://jmsyst.com/bundles/JMSI18nRoutingBundle
358 stars 159 forks source link

Add option to NOT override Symfony's default router #153

Open timvermaercke opened 9 years ago

timvermaercke commented 9 years ago

Hi

We're using two bundles (i18nRoutingBundle and one of our own) that will alter the Symfony routing. The problem we had is that our bundle was ignored because the i18n bundle always took the upper hand and our dynamic routing wasn't loaded.

We've found a solution to get them both working but for that we needed to add an option, whether or not the bundle's router replaces the standard Symfony router. If we do this, the JMSi18nBundle plays nicely with other bundles.

XWB commented 8 years ago

You can also extend I18nRouter:

class MyRouter extends I18nRouter
{
}
<service id="my_router" class="MyBundle\Routing\MyRouter" parent="jms_i18n_routing.router" public="false">
</service>

Make sure to load your own bundle behind the I18nRoutingBundle:

public function registerBundles()
{
    $bundles = array(
        new JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
        new MyBundle\Bundle(),
    );

    return $bundles;
}

Finally use a compiler pass to override the alias:

public function process(ContainerBuilder $container)
{
    $container->setAlias('router', 'my_router');
}
timvermaercke commented 7 years ago

This was no option for us. We fixed it by adding a custom CompilerPass.