我正在尝试在symfony 2应用程序中创建我的第一个服务,我收到此错误:
InvalidArgumentException: There is no extension able to load the
configuration for "my_app.myservice" (in
/path/to/src/MyApp/MyBundle/DependencyInjection/../Resources/config/services.yml).
Looked for namespace "my_app.myservice", found none.
我的配置似乎有问题,但我看不出它是什么。
这是我的 services.yml
services:
my_app.myservice:
class: MyApp\MyBundle\Service\MyService
我的服务看起来像这样
<?php
namespace MyApp\MyBundle\Service;
class MyService
{
public function run()
{
echo "hello world";
}
}
感谢您的帮助!
答案 0 :(得分:2)
只是为了确定 - 您在services.yml中有适当的缩进吗?
应该是:
services:
my_app.myservice:
class: MyApp\MyBundle\Service\MyService
不
services:
my_app.myservice:
class: MyApp\MyBundle\Service\MyService
答案 1 :(得分:0)
您的服务构造函数中是否有任何参数?
例如,我在所有服务中传递记录器。
结果是我必须在我的service.yml
中传递它 service.yml
services:
blog:
class:Site\Backend\BlogBundle\Service\BlogService
arguments: [@logger]
tags:
- { name: monolog.logger, channel: blog}
BlogService
public function __construct(LoggerInterface $logger){
$this->logger = $logger;
}