在 PhpStorm 警告方法 'withJson' 未找到(Slim Framework)
In PhpStorm warning method 'withJson' not found (Slim Framework)
在 PhpStorm 中我收到警告消息
"warning method 'withJson' not found" in \Psr\Http\Message\ResponseInterface" 在第行:
return $response->withJson($toReturn, 200);
代码:
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app->get('/bedrijven', function (Request $request, Response $response) {
require_once(CLASSES_PATH . "/class_bedrijven.php");
$Bedrijven = new Bedrijven();
$toReturn = $Bedrijven->get_bedrijven();
return $response->withJson($toReturn, 200);
});
我已经将 slim framework with composer 更新到最新版本 3.8.1,并在 PhpStorm 中添加了 Slim 作为插件。
Vendor 目录设置为 Sources 和 Excluded。
我能找到的唯一答案是在编辑器 -> 检查 -> PHP -> 未定义 -> 未定义方法中关闭 PhpStorm 中的警告消息。
有更好的解决方案吗?
方法withJson
没有在\Psr\Http\Message\ResponseInterface
中定义,而是在Slim\Http\Response
中定义(它实现了前者),这意味着这个方法与Slim框架有关。你可以试试这个:
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Slim\Http\Response as Response;
在 PhpStorm 中我收到警告消息 "warning method 'withJson' not found" in \Psr\Http\Message\ResponseInterface" 在第行:
return $response->withJson($toReturn, 200);
代码:
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app->get('/bedrijven', function (Request $request, Response $response) {
require_once(CLASSES_PATH . "/class_bedrijven.php");
$Bedrijven = new Bedrijven();
$toReturn = $Bedrijven->get_bedrijven();
return $response->withJson($toReturn, 200);
});
我已经将 slim framework with composer 更新到最新版本 3.8.1,并在 PhpStorm 中添加了 Slim 作为插件。 Vendor 目录设置为 Sources 和 Excluded。
我能找到的唯一答案是在编辑器 -> 检查 -> PHP -> 未定义 -> 未定义方法中关闭 PhpStorm 中的警告消息。
有更好的解决方案吗?
方法withJson
没有在\Psr\Http\Message\ResponseInterface
中定义,而是在Slim\Http\Response
中定义(它实现了前者),这意味着这个方法与Slim框架有关。你可以试试这个:
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Slim\Http\Response as Response;