Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony服务不存在_Php_Symfony_Service_Controller - Fatal编程技术网

Php Symfony服务不存在

Php Symfony服务不存在,php,symfony,service,controller,Php,Symfony,Service,Controller,我想在symfony2中将控制器用作服务。我在test\testBundle\Resources\services.yml文件中定义了服务: parameters: # user.example.class: test\testBundle\Example services: test.controller: class: test\testBundle\Controller\TestController 并调用控制器中的服务: $this->get('t

我想在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”


您可能忘记了从正在读取的配置文件(通常是app/config/config.yml)导入
services.yml
文件:

imports:
    - { resource: '@MyBundle/Resources/config.yml' }

将配置文件放在捆绑包中的
Resources/config
目录中是一种惯例,参见Symfony2文档:

imports:
    - { resource: '@MyBundle/Resources/config/config.yml' }