Ich erstelle erholsame API mit FOSRestBundle. Wenn ich Daten über Ajax mit GET-Methode senden, funktioniert alles in Ordnung. Aber ich muss Daten per POST senden, ich versuche, Werte von POST mit ParamFetcherListener zu erhalten, aber es gibt Nullwerte zurück. Wenn ich die Anfrage-Methode zu GET ändern, funktioniert es. Was mache ich falsch?FOSRestBundle ParamFetcher POST-Methode
Mein Code:
/**
* @Rest\View(statusCode=201)
* @QueryParam(name="test", description="test")
*/
public function createAction(Request $request, ParamFetcherInterface $paramFetcher)
{
$test = $paramFetcher->get('test'); // it's null
}
Und 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 }
Routing:
_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
Vielen Dank im Voraus.
sind es weitere Anmerkungen vor Methode Create? –
Nein, das ist alles. – r3m4k3
Sie können alle Routen in Ihrer Anwendung sehen, indem Sie 'php bin/console debug: router' anrufen. Bitte geben Sie auch Ihre Routing-Konfiguration an. –