Silex2:安全防火墙和语言环境 [英] Silex2: Security firewall and locale

查看:27
本文介绍了Silex2:安全防火墙和语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将当前语言环境添加到/user/login 或/user/logout 等路径?控制器确实支持{_locale}"占位符,但在安全模式中,它被报告为错误.

How do I add the current locale to paths like /user/login or /user/logout? Controllers do support the '{_locale}' placeholder, but within the security pattern it is reported as an error.

$app['security.firewalls'] = array(
    'login' => array(
        'pattern' => '^/user/login$',
    ),
    'secured_area' => array(
        'pattern' => '^.*$',
        'anonymous' => false,
        'remember_me' => array(),
        'form' => array(
           'login_path' => '/user/login',
           'check_path' => '/user/login_check',
        ),
       'logout' => array(
           'logout_path' => '/user/logout',
           'invalidate_session' => true,
       ),
    ),
 );

推荐答案

解决方案是在 'login_path' 中使用路由名称(控制器绑定),而不是完整路径.

The solution was to use the route name (controller bind) in 'login_path', not the full path.

$app->get('/{_locale}/user/login', function(Request $request) use ($app) {
    return $app['twig']->render('login.html.twig', array(
        'error'         => $app['security.last_error']($request),
    ));
})->bind('login');


$app['security.firewalls'] = array(
    'login' => array(
        'pattern' => '^/(de|en|fr|es)/user/login$',
    ),
    'main' => array(
        'pattern' => '^.*$',
        'anonymous' => false,
        'remember_me' => array(),
        'form' => array(
        'login_path' => 'login',
        'check_path' => '/user/login_check',
        'post_only' => true,
        'with_csrf' => true,
        'default_target_path' => 'homepage'
    ),
    'logout' => array(
        'logout_path' => '/user/logout',
        'invalidate_session' => true,
    )
);

这篇关于Silex2:安全防火墙和语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆