Slim Controller request, response and arguments unavailable

I need: use a custom class to receive an HTTP request and deal with it.

What I still have:

$app->group('/user', function () use ($app) {
   $app->post('/login', Auth::class . ':login');
}

And in my Auth class:

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
// also tried: use Slim\Http\Request; use Slim\Http\Response;

class Auth {

protected $container;

public function __construct(&$c) {
    $this->container = $c;
}

public function login(Request $request, Response $response, $args) {
     // NEED TO GET GET/POST/PUT Params here
     // When I Try to print $request, $response or $args, it returns empty
}

My code shows in the login function what I need: get the http parameters and request / response / args parameters. (I want to implement many functions in one class, I mean, I do not want to use __invoke ()) Another thing is that I do not understand if I am something like return $ response-> withJson ($ somearraydata, 200); the $ response variable really works. Why?

Thanks for any help!

+4
source share
1 answer

, ,
$ args ( ), .

, , : $ Request- > getParsedBody() [ '']

, -.:)

+4

Source: https://habr.com/ru/post/1677205/


All Articles