Reputation: 21
i have an error starting with Symfony2.
InvalidArgumentException in YamlFileLoader.php line 356: There is no extension able to load the configuration for "services" (in /Users/jm/Documents/Websites/www.brsymfony.dev/src/CalcBundle/DependencyInjection/../Resources/config/services.yml). Looked for namespace "services", found none
My services.yml look like and it has whitespaces correctly:
services:
Calculator:
class: CalcBundle\Services\Calculator
arguments:
- @doctrine.orm.default_entity_manager
ListOperations:
class: CalcBundle\Services\ListOperations
arguments:
- @doctrine.orm.default_entity_manager
Can anyone help me?
--
Yes, i have this code on CalcExtension.php inside DependencyInjection folder:
<?php
namespace CalcBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Class AppExtension
*/
class CalcExtension extends Extension
{
/**
* Loads a specific configuration.
*
* @param array $config An array of configuration values
* @param ContainerBuilder $container A ContainerBuilder instance
*
* @throws \InvalidArgumentException When provided tag is not defined in this extension
*
* @api
*/
public function load(array $config, ContainerBuilder $container)
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
);
$loader->load('services.yml');
}
}
Thanks in advance :)
Upvotes: 2
Views: 1968
Reputation: 583
Have you created the extension on the DependencyInjection folder? Should be CalcBundle/DependencyInjection/CalcExtension.php
You have the documentation with examples here http://symfony.com/doc/current/cookbook/bundles/extension.html
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('services.yml');
}
The services.yml should be located on CalcBundle/Resources/config/services.yml
Be careful because examples are creating parameters and services together into config.yml, you have to adapt it to your case (services.yml and parameters.yml separated, I would recommend your way)
You have the documentation with examples here
https://symfony.com/doc/current/book/service_container.html
Upvotes: 0