我使用了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);
}
}
帮我解决错误和感谢