This would work if you use the __invoke method instead of the action() method as name.
Example:
<?php
namespace App\Action\Home;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
final class HomeAction
{
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
array $args
): ResponseInterface {
$id = $args['id'];
$response->getBody()->write(sprintf('The ID is: %s', $id));
return $response;
}
}
My example shows an “invokable” class. Slim will pass the request, response and the route arguments to the __invoke method if you use define the route like this: $app->get('/company/{id}', GetCompany::class);