0
私はFOSRestBundleで安らかなAPIを作成しています。 GETメソッドを使用してajax経由でデータを送信すると、すべて正常に機能します。 しかし、POSTでデータを送信する必要があります。私はParamFetcherListenerでPOSTから値を取得しようとしますが、null値を返します。 リクエストメソッドをGETに変更すると動作します。 私は何が間違っていますか?FOSRestBundle ParamFetcher POSTメソッド
マイコード:
/**
* @Rest\View(statusCode=201)
* @QueryParam(name="test", description="test")
*/
public function createAction(Request $request, ParamFetcherInterface $paramFetcher)
{
$test = $paramFetcher->get('test'); // it's null
}
そしてconfig.yml:
fos_rest:
param_fetcher_listener: true
body_listener:
decoders:
json: fos_rest.decoder.json
view:
view_response_listener: true
formats:
xml: true
json: true
routing_loader:
default_format: json
format_listener:
rules:
- { path: '^/api/', priorities: ['json', 'xml'], fallback_format: 'html', prefer_extension: false }
ルーティング:事前に
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_info ANY ANY ANY /_profiler/info/{about}
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
object_all GET ANY ANY /api/objects
saved_object_all GET ANY ANY /api/saved_objects
saved_object_get GET ANY ANY /api/saved_objects/{id}
saved_object_new POST ANY ANY /api/saved_objects
saved_object_delete DELETE ANY ANY /api/saved_objects/{id}
object_test ANY ANY ANY /api/test
感謝。 POSTリクエストでコースデータの
は、任意のより多くの注釈は、メソッドcreateActionの前にあるのですか? –
いいえ、それだけです。 – r3m4k3
'php bin/console debug:router'を呼び出すことでアプリケーションのすべてのルートを見ることができます。あなたの質問にあなたのルーティング設定を含めてください。 –