Symfony FOSRestBundle错误:在null上调用成员函数get()。[路由或配置错误]
我的问题是:我有一个symfony 3应用程序。一个包用于Rest路由(因此我的包是RESTAPI),另一个包负责管理前端(Twig+Ajax)。 我使用fos_rest,但它似乎会产生问题 My config.yml:Symfony FOSRestBundle错误:在null上调用成员函数get()。[路由或配置错误],rest,symfony,fosrestbundle,symfony-3.3,Rest,Symfony,Fosrestbundle,Symfony 3.3,我的问题是:我有一个symfony 3应用程序。一个包用于Rest路由(因此我的包是RESTAPI),另一个包负责管理前端(Twig+Ajax)。 我使用fos_rest,但它似乎会产生问题 My config.yml: fos_rest: routing_loader: include_format: false view: view_response_listener: true format_listener: rul
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 }
My 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;
}
我用邮递员测试我的路线,它向我发送了一个错误
错误:调用null上的成员函数get()
尝试:$participants=$this->get('doctrine.orm.default\u entity\u manager')…
或者使用
$participants=$this->getdoctor()…
返回调用成员函数has()on null
使用$this->getdoctor()
和调用成员函数get()on null
使用$this->get('doctor.orm.default\u entity\u manager')
请粘贴更多信息。文件和发生错误的代码行将非常有用:)您的控制器是否定义为服务?就是这样。默认情况下,Appbundle在services.yml中声明为服务。我对行进行了注释,一切都很好。3.3和FOSRestBundle存在控制器自动接线错误的问题。基本上,容器没有被注入控制器,这导致$this->get()失败。我认为您最好使用S3.2,直到FOS捆绑包更新。