0
votes

In another question I asked how to generate routes dynamically in SF2 (Since I want to force prefix on routes), and it works fine:

How to add custom routes to Symfony 2 before container compilation?

The problem is that these routes are not cached, which may be not so good for performance. I wonder if I'm doing something wrong here, and if not perhaps there is a way to ask SF2 to cache my routes?

1

1 Answers

0
votes

I have followed this tutorial here which seems to work for me:

http://forum.symfony-project.org/viewtopic.php?t=38793&p=127825

To quote:

Loader:

namespace MyName\MyBundle;

use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

class MyRouteLoader extends Loader 
{
    public function supports($resource, $type=null) 
    {
        return 'my_new_resource_type' === $type;
    }

    public function load($resource, $type=null) 
    {
        $collection = new RouteCollection();
        $collection->addRoute(new Route(...));
        return $collection;
    }
}

Services:

services:
    my_route_loader:
        class: MyName\MyBundle\MyRouteLoader
        tags:
            - {name: routing.loader}