Router with variable path and with additional GET parameters in the url

Hi, how can I do to route the following URL?

URL: https://example.com/User/1s3ddfg2?username=1234&password=1234

$app->get(’User/{token:/(.+)[?]}’, ‘User:login’);

This is correct?
And how do I get the values ​​of the token and the GET parameters in my controller?

public function something($request, $response){
        $username =  $request->getParam('username');

extract token with args ‘user/token/???’

1 Like
{
  "message": "Slim Application Error",
  "exception": [
    {
      "type": "FastRoute\\BadRouteException",
      "code": 0,
      "message": "Regex \"/(.+)[?]\" for parameter \"token\" contains a capturing group",
      "file": "/var/www/example.com/htdocs/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php",
      "line": 145,

/User/AAAAA?username=user@mail.com&password=23456

$app->get(’User/{token}’, ‘User:login’);

$arrInputParams = $objRequest->getParams();
  ["username"]=>
  string(13) "user@mail.com"
  ["password"]=>
  string(5) "23456"

How to get the token value? (AAAAA)

Doing this from my phone, so forgive the brevity.

Your controller action method should take three parameters; request, response and arguments array. You’ll find the value that you’re looking for in the array :+1:

1 Like

Thanks, I was getting complicated with the regular expression and it was not necessary. It’s solved.

1 Like