Sonata Admin - 如何更改默认/管理员前缀

时间:2016-08-23 15:43:55

标签: symfony routes sonata-admin

我偶然发现了一个问题,我无法找到解决方案。

我想将默认的Sonata /admin网址路径前缀更改为其他内容。 我尝试将routing.yml路由admin_sonata_admin更改为/admin以外的其他内容,但仍然是默认的管理面板路径。真的很混乱。

如何更改默认/admin路径?

更新routing.yml列表):

app:
    resource: "@AppBundle/Controller/"
    type:     annotation

sonata_user_profile_show:
    resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"

admin:
    resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
    prefix:   /admin

sonata_user:
    resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
    prefix:   /admin

_sonata_admin:
    resource: .
    type:     sonata_admin
    prefix:   /admin
    defaults:
        _locale: "%locale%"

1 个答案:

答案 0 :(得分:3)

要在网址中更改默认管理员前缀,您需要首先在routing.yml更新,我想通过阅读您已经完成的评论,第二件事需要通过更改管理员在security.yml中进行更改防火墙模式和access_control规则,如果需要在应用以下更改后清除缓存

路由

admin_area:
    resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
    prefix: /panel

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /panel

sonata_user:
    resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
    prefix: /panel

防火墙

security:
    firewalls:
        admin:
            pattern:            /panel(.*)
            context:            user
            form_login:
                provider:       fos_userbundle
                login_path:     sonata_user_admin_security_login
                use_forward:    false
                check_path:     sonata_user_admin_security_check
                failure_path:   null
            logout:
                path:           sonata_user_admin_security_logout
                target:         sonata_user_admin_security_login
            anonymous:          true

    access_control:

        # Admin login page needs to be access without credential
        - { path: ^/panel/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/panel/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/panel/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/panel/, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] }