How to get all the parameters in a GET request with Silex?

2

I'm having my first contacts with the Silex framework.

I have the following script to be able to capture a GET parameter:

$app->get('/', function (Request $request, Silex\Application $app) {

    return sprintf('Meu nome é %s', $request->query->get('nome'));
});

Using get I can capture a specific url parameter. But how do I get all parameters? Is there any way to do this?

    
asked by anonymous 10.11.2016 / 18:17

1 answer

3

You can use $request->request->all() that will return an array with all parameters.

Additional

If you already know $request->query->get('nome') , you can place request parameters as method arguments, as long as you have the parameter set in the path ( pattern: /{nome} )

$app->get('/{nome}', function (Request $request, Silex\Application $app, $nome) {    
    return sprintf('Meu nome é %s', $nome);
});
    
10.11.2016 / 18:42