Slim PHP and GET Parameters

Solution 1:

You can do this very easily within the Slim framework, you can use:

$paramValue = $app->request()->params('paramName');

$app here is a Slim instance.

Or if you want to be more specific

//GET parameter

$paramValue = $app->request()->get('paramName');

//POST parameter

$paramValue = $app->request()->post('paramName');

You would use it like so in a specific route

$app->get('/route',  function () use ($app) {
          $paramValue = $app->request()->params('paramName');
});

You can read the documentation on the request object http://docs.slimframework.com/request/variables/

As of Slim v3:

$app->get('/route', function ($request, $response, $args) {
    $paramValue = $request->params(''); // equal to $_REQUEST
    $paramValue = $request->post(''); // equal to $_POST
    $paramValue = $request->get(''); // equal to $_GET

    // ...

    return $response;
});

Solution 2:

For Slim 3/4 you need to use the method getQueryParams() on the PSR 7 Request object.

Citing Slim 3 / Slim 4 documentation:

You can get the query parameters as an associative array on the Request object using getQueryParams().