2016-03-23 23 views
1

fos user bundleをSymfony 2.7にインストールしました。falseに設定するとalways_use_default_target_pathが機能しません

すべてうまくいきますが、リダイレクトに問題があります。私はいつも家に帰る:localhost/xxx/app_dev.php/。私のsecurity.yml

#security.yml 


security: 
    encoders: 
     FOS\UserBundle\Model\UserInterface: bcrypt 

    role_hierarchy: 
     ROLE_ADMIN:  ROLE_USER 
     ROLE_SUPER_ADMIN: ROLE_ADMIN 

    providers: 
     fos_userbundle: 
      id: fos_user.user_provider.username 

    firewalls: 
     main: 
      pattern: ^/ 
      form_login: 
       provider: fos_userbundle 

       csrf_provider: form.csrf_provider 
       always_use_default_target_path: false 
       default_target_path:   /
       target_path_parameter:   _target_path 
       use_referer:     false 

      logout:  true 
      anonymous: true 

    access_control: 
     - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/admin/, role: ROLE_ADMIN } 

どのような問題が生きることができますか?

答えて

1

ログインフォームを確認してください。入力フォームにはどの入力フィールドが含まれていますか?構成で

あなたが追加しました:

  target_path_parameter:   _target_path 

これはどこログイン後にユーザーをリダイレクトするかを決定するためにあなたのログインフォームで_target_path隠し入力フィールドを使用します。 (これは空の文字列かデフォルトの/と仮定します)

この行のコメントを外して試してみてください。アンドラーシュLacziの答えに

0

よろしく私は私自身の柔軟なソリューション(おそらくより良い1が存在)

ステップONEを作っ追加しました:

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

ステップ2::私は、行の次のsecurity.ymlに追加小枝でFOSUserBundle SecurityControllerをオーバーライドし、どこかに以下の行を追加:、私はログインするリダイレクト生成したい場所で、私は

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

ステップTHREEを追加しましたLoginActionの

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

ステップ4:上書きFOSUserBundleログインフォームの追加次の隠しフィールド:

<input type="hidden" name="_target_path" value="{{ targetPath }}" /> 
<input type="hidden" name="_failure_path" value="/login?targetPath={{ failurePath }}" /> 
関連する問題