我的问题:我有一个 symfony 3 应用程序。一个用于 Rest Route 的 Bundle(所以我的 bundle 是一个 rest API)和另一个管理前端的 Bundle(Twig + Ajax)。我使用 fos_rest,但它似乎有问题。
我的 config.yml:
fos_rest:
routing_loader:
include_format: false
view:
view_response_listener: true
format_listener:
rules:
- { path: '^/rest', priorities: ['json'], fallback_format: 'json' }
- { path: '^/', stop: true }
我的 routing.yml :
front:
resource: '@FrontBundle/Controller'
type: annotation
api:
resource: '@AppBundle/Controller'
type: rest
prefix: '/rest'
和我的 RestController 中的一条基本路线:
/**
* @Rest\View()
* @Rest\Get("/participants")
*
* @param Request $request
* @return mixed
*/
public function getParticipantsAction(Request $request)
{
$participants = $this->get('doctrine.orm.entity_manager')
->getRepository('AppBundle:Participant')
->findAll();
if (empty($participant)) {
return new JsonResponse(['message' => 'There is no participants'], Response::HTTP_NOT_FOUND);
}
return $participants;
}
我用邮递员测试我的路线,它给我发了一个错误Error: Call to a member function get() on null