Ich versuche (Statuscode) als Reaktion von REST-api zu bekommen, während sie nur Feldnamen und Fehlermeldung zurück, wie dieseYii2 Rest api kehrt nicht Antwortcode und Status
[{"field":"Email","message":"Email \"[email protected]\" has already been taken."}]
ich hinzugefügt habe Antwort
'response' => [
'class' => 'yii\web\Response',
'on beforeSend' => function ($event) {
$response = $event->sender;
if ($response->data !== null && Yii::$app->request->get('suppress_response_code')) {
$response->data = [
'success' => $response->isSuccessful,
'data' => $response->data,
];
$response->statusCode = 200;
}
},
],
so setzen Sie nur den Statuscode, wenn 'suppress_response_code' über' $ _GET' gesendet wird? – Blizz
Aber ich bekomme in keinem Fall eine Statusantwort .... – naCheex
@AliRaza versuche den zweiten Teil 'Yii :: $ app-> request-> get ('suppress_response_code') zu entfernen und teste es. Wenn es fehlschlägt, ist '$ response-> data' null. – SiZE