简体   繁体   English

Symfony2上的动态default_target_path

[英]Dynamic default_target_path on Symfony2

I'm developing an application with Symfony2 and FOSUserbundle. 我正在用Symfony2和FOSUserbundle开发应用程序。

When a user logs in on the system I want to redirect them to /user/username, were username obviously change with every user. 当用户登录系统时,我想将其重定向到/ user / username,显然每个用户的用户名都会更改。

One option of Security.yml is default_target_path. Security.yml的一个选项是default_target_path。 Is it possible to set default_target_path to a dynamic path or I need to override the class of FOSUB on charge of login. 是否可以将default_target_path设置为动态路径,或者我需要覆盖负责登录的FOSUB类。

The answer above is wrong, you have to register a service as the success_handler for your firewall implementing AuthenticationSuccessHandlerInterface (you can mimic DefaultAuthenticationSuccessHandler) 上面的答案是错误的,您必须为实现AuthenticationSuccessHandlerInterface的防火墙注册一个服务作为success_handler(可以模仿DefaultAuthenticationSuccessHandler)

right answer here: Symfony2 extending DefaultAuthenticationSuccessHandler 正确的答案在这里: Symfony2扩展DefaultAuthenticationSuccessHandler

Overwrite SecuredController and Templemate . 覆盖SecuredControllerTemplemate In controller when user is login, create variable and pass it to your templemate 在控制器中,当用户登录时,创建变量并将其传递给您的模板

<input type="hidden" name="_target_path" value="{{redirect_url}}" />

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

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