Reputation: 793
I'm building my first symfony bundle and for some reason I can't get configuration to work.
Configuration.php
..........
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('custom.yml');
..........
custom.yml
bd_config:
version: 2
ConfigExtension.php
$rootNode = $treeBuilder->root('bd_config');
$rootNode->
children()
->integerNode('version')->end()
->end();
return $treeBuilder;
And I get this error
There is no extension able to load the configuration for "bd_config" (in /Library/WebServer/symfony/src/BD/ConfigBundle/DependencyInjection/../Resources/config/custom.yml). Looked for namespace "bd_config", found none
What I'm doing wrong?
Upvotes: 0
Views: 682
Reputation: 1697
First of all, you're doing it wrong :).
Configuration.php
should build the tree (not the extension)*Extension.php
loads the resources (not the tree)Maybe it works then, but I don't know if BDConfigBundle
is b_d_config
in yml. I would use BdConfig
as bundlename and bd_config
as yml root.
Then I would import your yml in config.yml
:
config.yml
imports:
- { resource: custom.yml }
BdConfigStoreExtension.php
class BdConfigStoreExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$bdConfigNode = $this->processConfiguration($configuration, $configs);
// ...
}
}
Hope this helps ;).
Upvotes: 0
Reputation: 692
There is a naming convention on using bundle configs. Your config root have to be in the following format:
vendor_bundle
Where if your bundle name is in camel case and consists of more than one word (apart from Bundle and vendor name), then it contains further _ signs. Eg: CompanySuperSymfonyBundle
will be company_super_symfony
.
After that, you can set your configuration:
company_super_symfony:
version: 100
Treebuilder:
$rootNode->
children()
->integerNode('version')->end()
->end();
You don't have to load anything using the Loader, but you have to add your config as container parameter:
$container->setParameter('version', $config['version']);
And then, in your controller:
... = $this->container->getParameter('version');
Upvotes: 1