0

Atm i am trying to migrate php code

$routes->add(
    'index',
    new Route('/', ['_controller' => 'getIndex'])
);

to YML config

index:
    path:   /
    defaults: { _controller:  'getIndex' }

but i am getting an error

'There is no extension able to load the configuration for "index" (in /app/config\routes.yml).

YamlFileLoade just cant read this type of config, but why? I am using this guide http://symfony.com/doc/current/components/routing/introduction.html and my code to load configurations

$config = array(__DIR__ . '/app/config');
$loader = new YamlFileLoader($container, new FileLocator($config));
$loader->load('master.yml');
$collection = $loader->load('routing.yml');

already working perfectly with service container (master.yml) but doesnt with routings configuration.

6
  • 1
    Your routing needs to be in app/config/routing.yml or in added bundles. <-- That's for Symfony, ignore this~ Commented Mar 29, 2014 at 0:55
  • 1
    Are you using the correct YamlFileLoader (Symfony\Component\Routing\Loader\YamlFileLoader)? Also your $loader->load('master.yml') doesn't match your routes.yml filename. Commented Mar 29, 2014 at 0:58
  • routing.yml is already in config folder, i just gave an example with master.yml to say what YamlFileLoader working for another configuration file, but doesn't for routing.yml :) Updated code to avoid misunderstoods. Commented Mar 29, 2014 at 1:07
  • 1
    Are you using the correct YamlFileLoader read it? The services one will only allow parameters or services while the routing one will allow routes. Commented Mar 29, 2014 at 1:24
  • @Qoop please add this as an anwser, and i ll mark it, you are right, they have similar names, and i am using YamlFileLoader of DI component, not Routing one. Commented Mar 29, 2014 at 6:21

2 Answers 2

2

At first routing configuration is something different than DI configuration. You are now trying to load routes using the DI config mechanism.

To use routes, you should create a file app/config/routing.yml. This is where the routes life. If you want to put the routes in the bundle, you cannot use the DI extension class to load them. You have to include them in the app/config/routing.yml file, like this:

acme_demo_routes:
    resource: @AcmeDemoBundle/Resources/config/routes.yml
Sign up to request clarification or add additional context in comments.

Comments

1

Posting comment as answer as requested...

Are you using the correct YamlFileLoader read it? The services (DI) one will only allow parameters or services while the routing one will allow routes.

Routing => Symfony\Component\Routing\Loader\YamlFileLoader

DI => Symfony\Component\DependencyInjection\Loader\YamlFileLoader

1 Comment

We can not use the loader Symfony\Component\DependencyInjection\Loader\YamlFileLoader in Symfony\Component\ DependencyInjection\Extension. See Wouter J 's answer to find out how.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.