简体   繁体   English

登录Symfony后如何重定向到先前的请求

[英]How redirect to previous request after login in Symfony

I have a controller to download files only to register users, for example: 我有一个控制器仅下载文件来注册用户,例如:

www.myapp.com/download/123.jpg www.myapp.com/download/123.jpg

But if a register user enter in this link but in this moment isn't logged, the system send him to log in page. 但是,如果注册用户输入此链接但此刻未登录,则系统会将其发送到登录页面。

I need the user after of login, come back to the first url .../download/123.jpg 登录后需要用户,请返回第一个网址... / download / 123.jpg

How is it possible in Symfony2? Symfony2中怎么可能?

Thanks! 谢谢!

This is configured in the form_login section of your security firewall: 这是在安全防火墙的form_login部分配置的:

# login success redirecting options (read further below)
always_use_default_target_path: false
default_target_path:            /
target_path_parameter:          _target_path
use_referer:                    false

If you have changed always_use_default_target_path to true, then the user would always be redirected to "/". 如果将always_use_default_target_path更改为true,则用户将始终被重定向到“ /”。 Another possibility is that you're not displaying the _target_path hidden element in your login form. 另一种可能性是您没有在登录表单中显示_target_path隐藏元素。 Since use_referer is false by default, if this hidden field is missing the redirect would fall back to the default target path. 由于use_referer默认情况下为false,因此如果缺少此隐藏字段,则重定向将回退到默认目标路径。

This is all set up in security.yml and you can read more about configuration here: http://symfony.com/doc/current/reference/configuration/security.html 所有这些都在security.yml中设置,您可以在此处阅读有关配置的更多信息: http : //symfony.com/doc/current/reference/configuration/security.html

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

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