web-dev-qa-db-fra.com

Comment personnaliser les URL FOS UserBundle

J'ai installé FOSUserBundle et j'aimerais personnaliser les URL pour qu'elles soient /account/login, /account/register, /account/logout au lieu de /login, /register, /logout

Je sais que je peux modifier la configuration de routage du bundle, mais cela ne semble pas être la bonne façon.

33
petekaner

Comment remplacer/modifier les itinéraires de FOSUserBundle

Vous pouvez remplacer i.e le /register route dans votre app/config/routing.yml par re-déclaration it après importation des routes XML de FOSUserBundle en tant que ressources.

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /register

# ...

fos_user_registration_register:
    path:      /account/register
    defaults:  { _controller: FOSUserBundle:Registration:register }

... ou changez simplement le préfixe lors de l'importation:

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /account/register

# no need to override the route

C'est la même chose pour /login et /logout:

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

# ...

fos_user_security_login:
    path:      /account/login
    defaults:  { _controller: FOSUserBundle:Security:login, _method: POST }

fos_user_security_logout:
    path:      /account/login
    defaults:  { _controller: FOSUserBundle:Security:logout, _method: POST }

Une autre façon de remplacer les URL de connexion et de déconnexion

les chemins de connexion et de déconnexion peuvent également être configurés directement dans votre app/config/security.yml:

security:
    firewalls: 
        your_firewall:
            # ...
            form_login:
                login_path: /account/login  # instead of fos_user_security_login
                # ...
            logout:
                path: /account/logout       # instead of fos_user_security_logout
                # ...

Liste de tous les itinéraires de FOSUserBundle au format YAML

Vous pouvez directement modifier, puis les inclure dans votre app/config/routing.yml (pas besoin d'importer ceux que le bundle fournit alors comme ressources) ... ou de les mettre tous dans un seul fichier et de l'inclure comme ressource ...

# -> from @FOSUserBundle/Resources/routing/change_password.xml

fos_user_change_password:
    pattern: /profile/password/change
    defaults: { _controller: FOSUserBundle:ChangePassword:changePassword }
    requirements:
        _method: GET|POST

# -> from @FOSUserBundle/Resources/routing/group.xml

fos_user_group_list:
    pattern: /groups/list
    defaults: { _controller: FOSUserBundle:Group:list }
    requirements:
        _method: GET

fos_user_group_new:
    pattern: /groups/new
    pattern:
    defaults: { _controller: FOSUserBundle:Group:new }
    requirements:
        _method: GET

fos_user_group_show:
    pattern: /groups/{groupname}
    defaults: { _controller: FOSUserBundle:Group:show }
    requirements:
        _method: GET

fos_user_group_edit:
    pattern: /groups/{groupname}/edit
    defaults: { _controller: FOSUserBundle:Group:edit }
    requirements:
        _method: GET|POST

fos_user_group_delete:
    pattern: /groups/{groupname}/delete
    defaults: { _controller: FOSUserBundle:Group:delete }
    requirements:
        _method: GET

# -> from @FOSUserBundle/Resources/routing/profile.xml

fos_user_profile_show:
    pattern: /profile/show
    defaults: { _controller: FOSUserBundle:Profile:show }
    requirements:
        _method: GET

fos_user_profile_edit:
    pattern: /profile/edit
    defaults: { _controller: FOSUserBundle:Profile:edit }
    requirements:
        _method: GET|POST

# -> from @FOSUserBundle/Resources/routing/registration.xml

fos_user_registration_register:
    pattern: /registration
    defaults: { _controller: FOSUserBundle:Registration:register }
    requirements:
        _method: GET|POST

fos_user_registration_check_email:
    pattern: /registration/check-email
    defaults: { _controller: FOSUserBundle:Registration:checkEmail }
    requirements:
        _method: GET

fos_user_registration_confirm:
    pattern: /registration/confirm/{token}
    defaults: { _controller: FOSUserBundle:Registration:confirm }
    requirements:
        _method: GET

fos_user_registration_confirmed:
    pattern: /registration/confirmed
    defaults: { _controller: FOSUserBundle:Registration:confirmed }
    requirements:
        _method: GET

# -> from @FOSUserBundle/Resources/routing/resetting.xml

fos_user_resetting_request:
    pattern: /profile/password/reset
    defaults: { _controller: FOSUserBundle:Resetting:request }
    requirements:
        _method: GET

fos_user_resetting_send_email:
    pattern: /profile/password/reset
    defaults: { _controller: FOSUserBundle:Resetting:sendEmail }
    requirements:
        _method: POST

fos_user_resetting_check_email:
    pattern: /profile/password/reset/check-email
    defaults: { _controller: FOSUserBundle:Registration:checkEmail }
    requirements:
        _method: GET

fos_user_resetting_reset:
    pattern: /profile/password/reset/{token}
    defaults: { _controller: FOSUserBundle:Registration:reset }
    requirements:
        _method: GET|POST

# -> from @FOSUserBundle/Resources/routing/security.xml

fos_user_security_login:
    pattern: /login
    defaults: { _controller: FOSUserBundle:Security:login }
    requirements:
        _method: GET|POST

fos_user_security_check:
    pattern: /login_check
    defaults: { _controller: FOSUserBundle:Security:check }

fos_user_security_logout:
    pattern: /logout
    defaults: { _controller: FOSUserBundle:Security:logout }
    requirements:
        _method: GET|POST
80
Nicolai Fröhlich