Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PhpStorm warning method 'withJson' not found (Slim Framework)

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?

like image 419
Wow Avatar asked Aug 03 '17 13:08

Wow


People also ask

How many examples of Slim\HTTP\response::withjson are there?

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.

What does the method withjson () do in slim?

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.

How do I return a JSON file in slim?

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.

What is the response object in slim?

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.


1 Answers

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;
like image 122
Nima Avatar answered Oct 06 '22 03:10

Nima