我不知道如何在Silex中使用SecurityServiceProvider.我的配置是:
$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-> boot();在$app->注册(…)之前,它不会引发任何异常,但它可能根本无法启动,因为在生成登录表单Twig throws时:
Unable to generate a URL for the named route "_admin_login_check" as such route does not exist.
有an issue a few months ago可能是同样的问题,但它是关闭的,所以我猜应该现在修复
尝试在TwigServiceProvider之前注册SecurityServiceProvider时,我得到了同样的异常.
原文链接:https://www.f2er.com/php/132313.html我刚刚更改了注册顺序(Twig后的安全性),一切都开始正常工作:
// 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());