我想在symfony2中使用控制器作为服务。我在test'testBundle'Resources'services.yml
文件中定义了服务:
parameters:
# user.example.class: test'testBundle'Example
services:
test.controller:
class: test'testBundle'Controller'TestController
并调用我的控制器中的服务:
$this->get('test.controller');
但是symfony抛出以下异常:
您请求了一个不存在的服务"test.controller"。
您可能忘记从已经读取的配置文件导入services.yml
文件,通常是app/config/config.yml:
imports:
- { resource: '@MyBundle/Resources/config.yml' }
按照惯例,将配置文件放在捆绑包内的Resources/config
目录中。参见在Symfony2文档中导入配置:
imports:
- { resource: '@MyBundle/Resources/config/config.yml' }