在Silex中的/ admin路径下有登录路由

时间:2016-11-16 08:57:19

标签: php symfony silex

我使用此SecurityServiceProvider设置安装了Silex:

$this->app->register(new SecurityServiceProvider(), array(
            'security.firewalls' => array(
                'login' => array(
                    'pattern' => '^/login$',
                ),
                'secured' => [
                    'pattern' => '^/admin.*$',
                    'anonymous' => true,
                    'form' => array(
                        'login_path' => '/login',
                        'check_path' => '/admin/auth'
                    ),
                    'logout' => array(
                        'logout_path' => '/admin/logout'
                    ),
                    'users' => $this->app->share(function() use ($self) {
                        return new AuthenticationSuccessHandler($self->app['db']);
                    }),
                ]
            ),
            'security.role_hierarchy' => [
                'ROLE_USER' => [],
                'ROLE_BACKEND_USER' => ['ROLE_USER'],
                'ROLE_SUPERADMIN' => $this->getAllBasicRoleName() 

            ],
            'security.access_rules' => array(
                ['^/.*$', 'ROLE_USER'],
                ['^/admin.*$', 'ROLE_SUPERADMIN'],
                ['^/admin.*$', 'ROLE_BACKEND_USER']
            )
        ));

此设置解决:

/login -> login form
/admin -> secure area
/admin/logout -> logout form

但我需要在管理路径下可以访问登录表单,如下所示:

/admin/login -> login form UNDER ADMIN PATH!
/admin -> secure area
/admin/logout -> logout form

有办法做到这一点吗?

感谢。 S上。

1 个答案:

答案 0 :(得分:0)

您是否尝试过更改: 'login_path' => '/login','login_path' => '/admin/login',

我认为您还希望将'pattern'=> '^/login$',更改为'pattern'=> /admin(.*)