dstnlhhv791576 2013-08-02 17:34
浏览 56
已采纳

Silex SecurityServiceProvider抛出'Identifier'security.authentication_providers“未定义。”

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());

This just throws:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Identifier "security.authentication_providers" is not defined.'

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

  • 写回答

3条回答 默认 最新

  • douchengjue9892 2013-12-23 18:07
    关注

    I was getting the same exception when trying to register the SecurityServiceProvider before the TwigServiceProvider.

    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());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记