Symfony fosrestBundle的错误显示响应

Symfony fosrestBundle的错误显示响应,symfony,symfony-2.1,Symfony,Symfony 2.1,我在api中使用了fosrestBundle,但在为数据库调用数据时出现了错误。 这是一个错误: 必须将Symfony\Bundle\FrameworkBundle\Templating\EngineInterface的实例注入FOS\RestBundle\View\ViewHandler中才能呈现模板 代码AppController.php: <?php namespace Med\MedBundle\Controller; use Sensio\Bundle\Fra

我在api中使用了fosrestBundle,但在为数据库调用数据时出现了错误。 这是一个错误:

必须将Symfony\Bundle\FrameworkBundle\Templating\EngineInterface的实例注入FOS\RestBundle\View\ViewHandler中才能呈现模板

代码AppController.php:

<?php

    namespace Med\MedBundle\Controller;

    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use FOS\RestBundle\Controller\Annotations\RouteResource;
    use FOS\RestBundle\Controller\Annotations\View;
    use Med\MedBundle\Entity\Med;
    use Symfony\Component\HttpFoundation\JsonResponse;
    /**
     * @RouteResource("usse")
     */

    Class AppController extends Controller {

     public function getAction() {
            $em = $this->getDoctrine()->getManager();
            $test = $em->getRepository('MedMedBundle:Med')->findAll();
            return array('test'=>$test);
        }

    }
帮助我解决错误,谢谢

请尝试此解决方案
这是给symfony4的,但修复应该是一样的

请帮帮我。。
imports:
        - { resource: parameters.yml }
        - { resource: security.yml }
        - { resource: services.yml }

    # Put parameters here that don't need to change on each machine where the app is deployed
    # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
    parameters:
        locale: en

    framework:
        secret:          "%secret%"
        csrf_protection: ~
        form: ~
        session:
            handler_id: ~
    fos_user:
        db_driver: orm
        firewall_name: main
        user_class: AppBundle\Entity\User
        from_email:
            address: "test@test.com"
            sender_name: "Demo String"
        service:
            mailer: fos_user.mailer.twig_swift

    lexik_jwt_authentication:
        private_key_path: %jwt_private_key_path%
        public_key_path:  %jwt_public_key_path%
        pass_phrase:      %jwt_key_pass_phrase%
        token_ttl:        %jwt_token_ttl%
    nelmio_cors:
        defaults:
            allow_origin:   ["%cors_allow_origin%"]
            allow_methods:  ["POST", "PUT", "GET", "DELETE", "OPTIONS"]
            allow_headers:  ["content-type", "authorization"]
            expose_headers: ["link"]
            max_age:       3600
        paths:
            '^/': ~
    # Doctrine Configuration
    doctrine:
        dbal:
            driver: pdo_mysql
            host: '%database_host%'
            port: '%database_port%'
            dbname: '%database_name%'
            user: '%database_user%'
            password: '%database_password%'
            charset: UTF8
            # if using pdo_sqlite as your database driver:
            #   1. add the path in parameters.yml
            #     e.g. database_path: '%kernel.root_dir%/data/data.db3'
            #   2. Uncomment database_path in parameters.yml.dist
            #   3. Uncomment next line:
            #path: '%database_path%'

        orm:
            auto_generate_proxy_classes: '%kernel.debug%'
            naming_strategy: doctrine.orm.naming_strategy.underscore
            auto_mapping: true

    # Swiftmailer Configuration
    swiftmailer:
        transport: '%mailer_transport%'
        host: '%mailer_host%'
        username: '%mailer_user%'
        password: '%mailer_password%'
        spool: { type: memory }
    fos_rest:
        view:
            view_response_listener: 'force'
            formats:
                json: true
        format_listener:
            rules:
                - { path: '^/api', priorities: ['json'], fallback_format: json, prefer_extension: true }
                - { path: '^/', stop: true }
        param_fetcher_listener: true
        body_listener: 
            enabled: true
            array_normalizer:
                service: fos_rest.normalizer.camel_keys
                forms: true
            decoders:
                json: acme.decoder.json
                xml: fos_rest.decoder.xml
        view:
            view_response_listener: 'force'