2014-05-25 193 views
1

如何在用戶登錄後重定向?爲什麼我的代碼無法工作? 這裏我security.yml登錄後重定向fos用戶symfony

main: 
     pattern: ^/ 
     form_login: 
      provider: fos_userbundle 
      login_path: /login 
      check_path: /login_check 
      always_use_default_target_path: false 
      # default_target_path:   /home 
      # target_path_parameter:   _target_path 
      # use_referer:     false 
     oauth: 
      failure_path: /login 
      login_path: /login 
      check_path: /login 
      provider: fos_userbundle 
      resource_owners: 
       facebook:   "/login/check-facebook" 
      oauth_user_provider: 
       # service: hwi_oauth.user.provider.fosub_bridge 
       service: project_home_userprovider 

     anonymous: ~ 
     logout: 
      path: /logout 
      target: /login 


access_control: 
    - { path: ^/login$, roles: [IS_AUTHENTICATED_ANONYMOUSLY] } 
    - { path: ^/admin, roles: [ROLE_ADMIN] } 
    - { path: ^/murid, roles: [ROLE_MURID] } 

我這裏路由

murid: 
    resource: "@muridBundle/Resources/config/routing.yml" 
    prefix: /

admin: 
    resource: "@adminBundle/Resources/config/routing.yml" 
    prefix: /admin 

home: 
    resource: "@homeBundle/Resources/config/routing.yml" 
    prefix: /

fos_user_security: 
    resource: "@FOSUserBundle/Resources/config/routing/security.xml" 

fos_user_profile: 
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml" 
    prefix: /profile 

fos_user_resetting: 
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml" 
    prefix: /resetting 

fos_user_change_password: 
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml" 
    prefix: /profile 

hwi_oauth_security: 
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml" 
    prefix: /login 

hwi_oauth_connect: 
    resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml" 
    prefix: /login 

hwi_oauth_redirect: 
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml" 
    prefix: /login 

facebook_login: 
    pattern: /login/check-facebook 

登錄成功後,它總是直接到symfony的主頁..不能ü幫助我嗎?如何重定向到具有不同ROLE的另一個頁面?

回答

0

你需要定義default_target_path。在使用OAuth的情況下,您應該定義它。

main: 
    form_login: 
     default_target_path: "/your-path" 
    oauth: 
     default_target_path: "/your-path" 

如果要根據角色檢查this solution更改default_target_path。