Similar question has been here a few times already but unfortunately I wasn't able to find the help needed in there.
I am trying to create a custom extension class in Symfony (3.1). I am following the cookbook [1,2] but no matter what I try, I get the error
InvalidArgumentException in YamlFileLoader.php line 404: There is no extension able to load the configuration for "czechnology_tools" (in [path_to_project]\src\Czechnology\ToolsBundle\DependencyInjection/../Resources/config\holidays.yml). Looked for namespace "czechnology_tools", found none
classCzechnologyToolsExtension
:
<?php
namespace Czechnology\ToolsBundle\DependencyInjection;
// use ...
class CzechnologyToolsExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('holidays.yml');
}
}
and the corresponding Configuration.php
in the same directory:
<?php
namespace Czechnology\ToolsBundle\DependencyInjection;
// use ...
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('czechnology_tools');
$rootNode
->children()
->scalarNode('calendar')->defaultValue('default')->end()
->end()
;
return $treeBuilder;
}
}
In the YAML file, I currently just have dummy content, trying to get it to work at all. holidays.yml
:
czechnology_tools:
calendar: foo
If I try to debug in console, I get this:
$ bin/console config:dump-reference czechnology_tools
# Default configuration for extension with alias: "czechnology_tools"
czechnology_tools:
calendar: default
So it seems to be that the extension is set correctly, with the correct alias. However, I still cannot get over the exception. Any hints?
My guess is that somewhere is your bundle architecture, there is a typo (maybe intentional, a bundle class named differently than the extension, ...).
First, run
bin/console debug:config
, in order to see if your bundle appears with a different alias of the one you're trying to use, you should have an output containing a line that looks like:If it doesn't appear at all, add the following to your bundle class:
Plus, add the following method to your bundle extension:
Hope it solves the issue.