设置为false时,always_use_default_target_path不起作用

时间:2016-03-23 11:43:31

标签: php symfony security fosuserbundle

我在Symfony 2.7中安装了circle circle:: operator++() // prefix version { Area = Area * 2.0; return *this; } circle& circle::operator++( int n ) { //postfix version if( n != 0 ) // Handle case where an argument is passed. //some code else Area = Area * 2.0; // Handle case where no argument is passed. return *this; } int main() { class circle c1(4, 1, -1), c2(12, 4, 6); c1.output(); c1++; ++c1; c1.output(); system("pause"); return 0; }

一切正常但我有重定向问题。它总是将我重定向到家:fos user bundle。我的security.yml

localhost/xxx/app_dev.php/

可以存在什么问题?

2 个答案:

答案 0 :(得分:1)

检查您的登录表单,它包含哪些输入字段?

在您添加的配置中:

            target_path_parameter:          _target_path

这将使用您登录表单中的_target_path隐藏输入字段来确定登录后重定向用户的位置。 (我想这是一个空字符串或默认为/)

取消注释此行并试一试。

答案 1 :(得分:0)

关于Andras Laczi的回答,我添加了自己的灵活解决方案(可能存在更好的解决方案)

第一步:我在行后添加了security.yml:

firewalls:
    main:
         form_login:
            ...               
            failure_path_parameter: _failure_path

第二步:在twig中,在我想要生成重定向到登录的地方,我添加了

  <a href="{{ path('fos_user_security_login')}}?targetPath={{ app.request.attributes.get('_route') }}">Log in</a>

第三步:覆盖FOSUserBundle SecurityController,并在LoginAction中的某处添加以下行

$targetPath = $request->query->get('targetPath', 'app_index');
$failurePath = $targetPath;

第四步:覆盖FOSUserBundle登录表单,添加以下隐藏字段:

<input type="hidden" name="_target_path" value="{{ targetPath }}" />  
<input type="hidden" name="_failure_path" value="/login?targetPath={{ failurePath }}" />