Ajouve
Ajouve

Reputation: 10089

route with parameters in yml Symfony2

I'd like to add parameters on my routes that I use in yml, for example in security.yml

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            login_path: project_main_homepage
            default_target_path: project_user_profile
            failure_path: project_main_homepage

If I failed the login I will be redirect to project_main_homepage (http://www.mywebsite.com) but for example I'd like to be redirected to http://www.mywebsite.com?user=0 is there a solution to do that ?

Thanks

Upvotes: 0

Views: 1033

Answers (2)

Matteo Poile
Matteo Poile

Reputation: 61

Have you tried to add your parameters in /app/config/parameters.yml and to use them in routing.yml and in security.yml surrounded by %?

For example:

app/config/parameters.yml  
your_param: xxx

app/config/routing.yml
your_route:  
    pattern:  /%your_param%/{_locale}  
    defaults: { _controller: YourBundle:Main:index }

Upvotes: 0

joe42
joe42

Reputation: 657

I don't think it is possible to add a URL get parameter directly in the security.yml file but this is totally possible by creating an authentication handler where you create your own RedirectResponse to a route (with parameters) of your choosing. Check this article on creating an authentication handler in symfony.

Another alternative is to create a second route that has a URL parameter to redirect to the same action, not sure if that would suit your needs since it would be a different URL.

Upvotes: 1

Related Questions