Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony FOSRestBundle错误:在null上调用成员函数get()。[路由或配置错误]_Rest_Symfony_Fosrestbundle_Symfony 3.3 - Fatal编程技术网

Symfony FOSRestBundle错误:在null上调用成员函数get()。[路由或配置错误]

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

我的问题是:我有一个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:
        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捆绑包更新。