简体   繁体   English

yml Symfony2中带有参数的路由

[英]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 我想在yml中使用的路由上添加参数,例如在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 ? 如果登录失败,我将被重定向至project_main_homepage( http://www.mywebsite.com ),但例如,我想重定向至http://www.mywebsite.com?user=0,是否有解决方案要做到这一点 ?

Thanks 谢谢

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. 我认为不可能直接在security.yml文件中添加URL get参数,但这完全可以通过创建身份验证处理程序来实现,在该处理程序中,您可以创建自己的RedirectResponse到选择的路由(带有参数)。 Check this article on creating an authentication handler in symfony . 查看有关在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. 另一种选择是创建第二个路由,该路由的URL参数重定向到同一操作,因为它是不同的URL,所以不确定是否满足您的需求。

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 %? 您是否尝试过将参数添加到/app/config/parameters.yml中,并用在routing.yml和%包围的security.yml中?

For example: 例如:

app/config/parameters.yml  
your_param: xxx

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM