bug显示fosrestBundle的响应

时间:2017-07-09 16:51:40

标签: symfony symfony-2.1

我使用了fosrestBundle for api,但是当我为数据库调用数据时我有bug。 这是错误:

  

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

代码AppController.php:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="css.css">
    <title>title</title>
  </head>
  <body>
      
      <div id="first">
        <div id="central"></div>
      </div>
  
  </body>
</html>

code config.yml:

<?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);
        }

    }

帮我解决错误和感谢

1 个答案:

答案 0 :(得分:0)

请尝试此解决方案https://stackoverflow.com/a/48090947/1031304 这是symfony4,但修复应该是相同的