How to pass normal parameters to URL in symfony?

I am trying to pass parameters through a regular sequence, as such:

/user/login?foo=bar&abc=123

Unfortunately, nowhere in any data in the instance sfRoutedoes the data contain data for fooor abc. How to fix it?

Edit: Here is the code I use for Tom's query:

/apps/api/config/routing.yml:

login:
  url:   /user/login
  param: { module: user, action: login }

/apps/api/modules/user/actions/actions.class.php:

class userActions extends sfActions {
    public function executeLogin(sfWebRequest $request) {
        echo '<pre>'.print_r($this->getRoute(), true).'</pre>';
    }
}

What is it. The output shows that it $this->getRoute()does not contain information about fooor abcwhen I pass them in the query line with the URL "/ user / login? Foo = bar & abc = 123".

+3
source share
3 answers

$request, sfRoute:

$request->getParameter('foo')

, , , :

public function executeSomeAction($request)  {  }

$_SERVER['QUERY_STRING'] Symfony, .

UPDATE:

, , , . , , $request, . :

$params_typed = $request->getParameterHolder();  // ... and grab them from here

... .

, .

:

, :

routing.yml :

login:
  url:   /user/login
  param: { module: user, action: login, foo: something, abc: something }

:

$full_path = sfContext::getInstance()->getRouting()->getCurrentInternalUri();
+2

factories.yml :

routing:
  class: sfPatternRouting
  param:
    extra_parameters_as_query_string: true
+1

Please note that if you want to use the "extra_parameters_as_query_string: true" parameter, you must remove the last star of your route:

default:
  url:   /:module/:action
+1
source

Source: https://habr.com/ru/post/1785788/


All Articles