Get params in middleware

Hello,

I’ve a strange issue that i don’t understand.

I defined a extended class from Slim/App (with this following code)

class App extends Slim\App
{
public function __construct($config = [])
{
    if (!isset($config)) $config = [];

    // define Slim Settings
    $config = [
        'settings' => [
            'httpVersion' => '1.1',
            'responseChunkSize' => 4096,
            'outputBuffering' => 'append',
            'displayErrorDetails' => DEBUG,
            'determineRouteBeforeAppMiddleware' => true,
            'addContentLengthHeader' => true,
            'routerCacheFile' => false,
        ],
        'configFile' => $config,
    ];

    parent::__construct($config);

    $container = $this->getContainer();

    var_dump($container->get('settings'));

The dump show the ‘determineRouteBeforeAppMiddleware’ value : “true” (it’s good)

I use this following code to dump the $params object in the middleware (cf: last answer on https://github.com/slimphp/Slim/issues/1505)

public function __invoke(Request $request, Response $response, callable $next)
{
    $logger = $this->di->logger;
    $logger->addDebug("Middleware ValidationArgs start");
    try {
        $route = $request->getAttribute('route');
        $params = $route->getArguments();
        var_dump($params);
    }

I get this result with a GET on “https://api.mysite.com/?test=test” :

array(0) {
}

Why i don’t get an array with parameter ‘test’…?

There is something, i did not understand but what ?

Thanks for your help

test is a query parameter, not a route argument. Hence you can get at it using:

$test = $request->getParam('test');

It’s right, thanks :slight_smile: