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

Asked

Viewed 238 times

2

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

I have the following script to capture a parameter GET:

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

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

When using get i can capture a specific parameter of the url. But how do I get all the parameters? Is there any way to do this?

  • 1

    Take a look if this helps http://stackoverflow.com/questions/10455336/how-do-i-obtain-all-the-get-parameters-on-silex

1 answer

3


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


Additional

Outside the option you already know $request->query->get('nome'), you can put the request parameters as arguments of the method, provided you have the parameter defined in the route (pattern: /{nome})

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.