我从Symfony2开始时出错。
YamlFileLoader.php第356行中的InvalidArgumentException: 没有扩展程序可以加载"服务" (在/Users/jm/Documents/Websites/www.brsymfony.dev/src/CalcBundle/DependencyInjection/../Resources/config/services.yml)。寻找命名空间"服务",找不到
我的services.yml看起来像是有正确的空格:
services:
Calculator:
class: CalcBundle\Services\Calculator
arguments:
- @doctrine.orm.default_entity_manager
ListOperations:
class: CalcBundle\Services\ListOperations
arguments:
- @doctrine.orm.default_entity_manager
任何人都可以帮助我吗?
-
是的,我在DependencyInjection文件夹中的CalcExtension.php上有这段代码:
<?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');
}
}
提前致谢:)
答案 0 :(得分:0)
您是否在DependencyInjection文件夹上创建了扩展程序?应该是CalcBundle / DependencyInjection / CalcExtension.php
您的文档包含示例 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');
}
services.yml应位于CalcBundle / Resources / config / services.yml
上要小心,因为示例正在将参数和服务一起创建到config.yml中,你必须根据你的情况调整它(services.yml和parameters.yml分开,我建议你的方式)
您的文档包含示例