问题描述
我不知道如何在Silex
中使用SecurityServiceProvider
.我的配置是:
I can't figure out how to use SecurityServiceProvider
in Silex
. My configuration is:
$app['security.firewalls'] = array(
'admin' => array(
'pattern' => '^/_admin/.+',
'form' => array('login_path' => '/_admin/', 'check_path' => '/_admin/login_check'),
'logout' => array('logout_path' => '/_admin/logout'),
'users' => array(
'admin' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsR...'),
),
),
);
$app->register(new Silex\Provider\SecurityServiceProvider());
这只是抛出:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Identifier "security.authentication_providers" is not defined.'
根据文档,在某些情况下,如果您想在处理请求之外访问安全功能,则必须致电$app->boot();
,但这不是我的情况.
如果我在$app->register(...)
之前调用$app->boot();
,它不会引发任何异常,但可能根本无法启动,因为然后在生成登录表单时,Twig会抛出:
According to the documentation in some cases when you want to access Security features outside of the handling of a request you have to call $app->boot();
but this isn't my situation.
If I call $app->boot();
before $app->register(...)
it doesn't raise any exception but it probably doesn't boot at all because then in generating login form Twig throws:
Unable to generate a URL for the named route "_admin_login_check" as such route does not exist.
几个月前有一个一个问题,可能存在相同的问题,但已关闭,因此我想应该现在就解决
There's an issue a few months ago with probably the same problem but it's closed so I guess it should be fixed now
推荐答案
在尝试在TwigServiceProvider
之前注册SecurityServiceProvider
时,我遇到了相同的异常.
I was getting the same exception when trying to register the SecurityServiceProvider
before the TwigServiceProvider
.
我刚刚更改了注册顺序(安全 之后 Twig ),一切开始正常运行:
I just changed the registering order (Security after Twig) and everything started to work fine:
// Twig service
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => sprintf("%s/../views", __DIR__),
));
// Security service
$app["security.firewalls"] = array();
$app->register(new Silex\Provider\SecurityServiceProvider());
这篇关于Silex SecurityServiceProvider抛出“标识符""security.authentication_providers",没有定义.'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!