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