1
votes

I'm trying to dynamically load yml routing files from different bundles according to values in my DB. I've followed the cookbook to create a custom route loader, but I'm having an error when importing a file. I'm working on Symfony 2.3. My routing is working properly when I add the collection manually in the routing.yml file.

I've created a service to load the resources :

class ExtraLoader implements LoaderInterface
{
    private $loaded = false;

    public function load($resource, $type = null)
    {
        if (true === $this->loaded) {
            throw new \RuntimeException('Do not add the "extra" loader twice');
        }

        $loader = new AdvancedLoader($this->getResolver());
        $routes = new RouteCollection();

        $route = $loader->import('@ERPExsecBBundle/Resources/config/routing.yml');
        $route->addPrefix('/Production/');
        $routes->addCollection($route);

        $this->loaded = true;

        return $routes;
    }

    [...]
}

And an advanced loader as described in the cookbook :

class AdvancedLoader extends Loader
{
    public function __construct($resolver) {
        $this->resolver = $resolver;
    }

    public function load($resource, $type = null)
    {
        $collection = new RouteCollection();
        $type = 'yaml';
        $importedRoutes = $this->import($resource, $type);
        $collection->addCollection($importedRoutes);
        return $importedRoutes;
    }

    public function supports($resource, $type = null)
    {
        return $type === 'advanced_extra';
    }
}

But I'm getting an error :

Fatal error: Uncaught exception 'Symfony\Component\Config\Exception\FileLoaderLoadException' with message 'Cannot load resource "@ERPExsecBBundle/Resources/config/routing.yml". Make sure the "ERPExsecBBundle/Resources/config/routing.yml" bundle is correctly registered and loaded in the application kernel class.' in C:\Program Files\wamp\www\alimerp\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\Loader.php on line 77

Why am I getting this error ?

2

2 Answers

2
votes

In the cookbook they say :

# app/config/routing.yml
AcmeDemoBundle_Extra:
    resource: .
    type: extra

where "type" should match the type of your AdvancedLoader

 public function supports($resource, $type = null)
 {
     return $type === 'advanced_extra';
 }

You should try to replace "extra" by "advanced_extra" in your app/config/routing.yml

-1
votes

Have you registered the bundle ERPExsecBBundle in your AppKernel.php ?