2017-07-02 11 views
0

私の問題:私はsymfony 3アプリを持っています。 Rest Route用のバンドル(私のバンドルは残りのAPIなので)とフロント(Twig + Ajax)を管理する別のバンドル。 私はfos_restを使用していますが、問題があるようです。Symfony FOSRestBundleエラー:ヌルのメンバー関数get()を呼び出します。 [ルーティングまたは設定エラー]

マイ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内の1つの基本的なルート:

/** 
* @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

+0

3.3とFOSRestBundleが誤っautowiredされているコントローラとの問題を抱えています。基本的にコンテナはコントローラに注入されていないため、$ this-> get()は失敗します。私はあなたの最善の策は、FOSバンドルが更新されるまでS3.2を使うことだと思います。 – Cerad

答えて

0

はして試してみてください:$participants = $this->get('doctrine.orm.default_entity_manager')...

または$participants = $this->getDoctrine()...

+0

'$ this-> getDoctrine()'と '$ this-> get( 'doctrine.orm')を使って' nullのメンバー関数への呼び出し ' .default_entity_manager ') ' –

+0

いくつかの情報を貼り付けてください。エラーが発生したファイルとコード行は役に立ちます:) –

+0

コントローラはサービスとして定義されていますか? –

関連する問題