6

I've recently started separating out our custom bundles from our Symfony2 app so that they can be shared across multiple projects. I have successfully got them into their own repositories and included back into the main app via Composer. I know I have to register them in AppKernal, but I was hoping that I wouldn't have to link directly to their routing.yml and config.yml files from the ones in the /app/config/*.yml.

Is there a way to automatically include the config files from bundles within the vendors folder?

Craig
  • 8,093
  • 8
  • 42
  • 74

2 Answers2

0

It turns out a colleague had done this before with config.yml pointed me to this documentation

http://symfony.com/doc/current/cookbook/bundles/extension.html#using-the-load-method

By adding the following to the load() function in your bundle's extension you can have it auto load the various configuration files

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
$loader->load('services.yml');

However this doesn't work with routing.yml because it thinks it has to load an extension matching the name of each route.

Craig
  • 8,093
  • 8
  • 42
  • 74
  • You need to use a custom loader to load a route, you can find an example here: http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html – Snroki Feb 13 '15 at 09:01
  • 1
    The docs say "To load routes from some custom source (i.e. from something other than annotations, YAML or XML files)", but my routes are in standard yaml format and work when included from other routing.yml files directly. I don't think I need a custom loader, I just need to trigger the standard one. – Craig Feb 15 '15 at 20:57
-1

Please see my answer - https://stackoverflow.com/a/58140085/1274890

Also as per https://symfony.com/doc/current/bundles/override.html#routing

Routing is never automatically imported in Symfony. If you want to include the routes from any bundle, then they must be manually imported from somewhere in your application (e.g. config/routes.yaml).

R Sun
  • 1,353
  • 14
  • 17