2

I'd like to call an .yml file located in app/config from my controller.

Here is the code :

$menu_yml = __DIR__.'%kernel.root_dir%/app/config/main_menu.yml';
$menu = Yaml::parse($menu_yml);

I've tried many options, from this to FileLocator or Finder, but i can't reach out of the bundle. Any ideas ?

Thanks a lot !

DonCallisto
  • 29,419
  • 9
  • 72
  • 100
Cholesterol
  • 177
  • 2
  • 10
  • Possible duplicate content : http://stackoverflow.com/questions/4821692/how-do-i-read-configuration-settings-from-symfony2-config-yml – Antoine Subit Sep 24 '15 at 09:42
  • 2
    if you really want to use a new yml file from the app/config folder i would suggest that you import it in your config.yml so that you can access it from the container (it will be autoload by the dependency injection). If you want to learn more: http://symfony.com/doc/current/cookbook/configuration/configuration_organization.html – Snroki Sep 24 '15 at 09:46

1 Answers1

1

The kernel.root_dir is the absolute path of the root dir of the symfony application so you don't need the __DIR__ . But you need to ask to the container the value of the params.

As example, you can do (in your controller):

$root_dir = $this->container->getParameter('kernel.root_dir');
$menu_yml = $root_dir.'/app/config/main_menu.yml';
$menu = Yaml::parse($menu_yml);

You can check the value of the parameters via command line with the command:

app/console container:debug --parameter=kernel.root_dir

Hope this help

Matteo
  • 37,680
  • 11
  • 100
  • 115