且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Slim 3中间件重定向

更新时间:2023-11-17 08:18:40

您需要return响应.不要忘记requestresponse对象是不可变的.

You need to return the response. Don't forget that the request and response objects are immutable.

return $response = $response->withRedirect(...);

我有一个类似的身份验证中间件,这就是我做的方法,它还添加了403(未授权)标头.

I have a similar auth middleware and this is how I do it which also adds a 403 (unauthorized) header.

$uri = $request->getUri()->withPath($this->router->pathFor('home'));
return $response = $response->withRedirect($uri, 403);