具有状态 400 和重定向的 Slim return 响应

Slim return response with status 400 and redirect

您好,如果 post 请求失败,我正在尝试 return 状态代码 400,然后将用户重定向回他们进入 post 的页面。

我试过以下例子:

return $response->withRedirect('/view/companies', 400);

这只是 return 一个白页

return $response->withStatus(400);

这只是 return 一个白页

return $response->withJson([], 400);

这只是 return 顶部有这个的白页

return $response->withRedirect('/view/companies');

这 return 使用户返回页面,但没有通过 400 错误。

根据https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections

HTTP redirects are responses with a status code of 3xx.

因此状态代码为 400 的重定向是不可能的(尽管它在 Slim 3.9 版之前有效,参见 https://github.com/slimphp/Slim/issues/2355)。