In PhpStorm I get the warning message "warning method 'withJson' not found" in \Psr\Http\Message\ResponseInterface" at te line:
return $response->withJson($toReturn, 200);
The code:
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);
});
I already updated slim framework with composer to latest version 3.8.1 and added Slim as a plugin in PhpStorm. The Vendor directorie is set to Sources and Excluded.
The only answer I can find is to turn off the warning messages in PhpStorm in Editor -> Inspections -> PHP -> Undefined -> undefined method.
Is there a better solution?
PHP Slim\Http Response::withJson - 16 examples found. These are the top rated real world PHP examples of Slim\Http\Response::withJson extracted from open source projects. You can rate examples to help us improve the quality of examples.
This method returns a copy of the Response object that contains the new body. Slim’s Response object has a custom method withJson ($data, $status, $encodingOptions) to help simplify the process of returning JSON data.
Returning JSON. Slim’s Response object has a custom method withJson($data, $status, $encodingOptions) to help simplify the process of returning JSON data. The $data parameter contains the data structure you wish returned as JSON. $status is optional, and can be used to return a custom HTTP code.
The Response object is immutable. This method returns a copy of the Response object that has the appended header value. An HTTP response typically has a body. Slim provides a PSR-7 Response object with which you can inspect and manipulate the eventual HTTP response’s body.
Method withJson
is not defined in \Psr\Http\Message\ResponseInterface
but in Slim\Http\Response
(which implements the former), that means this method is something related to Slim framework. You can try this:
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Slim\Http\Response as Response;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With