[英]Slim3 Cannot use object of type Slim\Http\Response as array
我在将错误输出添加到JWT中间件设置时遇到麻烦。
我收到此错误: Cannot use object of type Slim\\Http\\Response as array
我正在使用Slim 3和slim-jwt-auth软件包,我正在使用https://github.com/tuupola/slim-jwt-auth#error上的文档中的示例代码
区别是我叫\\Slim\\Middleware\\JwtAuthentication
而不是Tuupola\\Middleware\\JwtAuthentication
。 如果我使用该类找不到。 一切工作正常,直到我想将错误输出添加到中间件设置中,这是我的代码:
$app->add(new \Slim\Middleware\JwtAuthentication([
"path" => "/mypath",
"passthrough" => "/mypath/get-auth",
"secret" => getenv("SKEY"),
"secure" => false,
"error" => function ($response, $args) {
$data = array();
$data["status"] = "error";
$data["message"] = $args["message"];
return $response
->withHeader("Content-Type", "application/json")
->getBody()->write(
json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
]));
错误输出表明它来自行$data["message"] = $args["message"];
。
我是在看问题但没有看到问题吗?
"error"
关闭的函数签名为:
function ($request, $response, $args): Response
您缺少代码中的第一个参数,因此当您使用$args
,您将获得Response
对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.