Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 登录时重定向_Symfony_Symfony 2.3 - Fatal编程技术网

Symfony 登录时重定向

Symfony 登录时重定向,symfony,symfony-2.3,Symfony,Symfony 2.3,如果用户经过身份验证,我想在登录操作中执行重定向 我的安全 firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false login: pattern: ^/(en|de)/login security: false secured_area: pattern: ^/

如果用户经过身份验证,我想在登录操作中执行重定向

我的安全

    firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login:
        pattern:  ^/(en|de)/login
        security: false

    secured_area:
        pattern:    ^/
        anonymous:  ~
        http_basic:
            realm: "Secured Area"
        form_login:
            check_path: frontend_account_security_check
            login_path: frontend_account_login
            #use_referer:        true
            #always_use_default_target_path: true
            default_target_path: frontend_main_index
            #default_target_path: frontend_account_my_account
            #target_path_parameter: frontend_account_my_account
        logout: 
            path:   /de/secured/logout
            target: /de/
            #default_target_path: frontend_account_login
            #anonymous: ~
        http_basic:
            realm: "Secured Demo Area"



access_control:
    #- { path: ^/secured/en/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/(en|de)/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
我的行动:

    $auth = $this->get('security.context')->getToken()->getUser();
        if ($auth == 'anon.') {
            $auth = FALSE;
        } else {
           return $this->redirect($this->generateUrl('frontend_main_index'));
        }
我的错误: 对非对象调用成员函数getUser()

我还尝试了:
$this->get('security.context')->isgrated('ROLE\u USER')
,错误如下:

安全上下文不包含身份验证令牌。一个可能的原因可能是没有为此URL配置防火墙


如果用户登录,我可以执行重定向

问题似乎在于这一部分:

login:
    pattern:  ^/(en|de)/login
    security: false
从您的
security.yml
中删除此项,您应该能够使用

$this->get('security.context')->isGranted('ROLE_USER')
并相应地重定向。我认为这与防火墙不共享其安全上下文有关。有关的详细说明,请参见文档


还请注意,您应该删除

    http_basic:
        realm: "Secured Area"


$this->get('security.context')->isgrated('ROLE\u USER')
应该可以工作。这行代码会导致什么样的错误?您的完整登录看起来如何?谢谢您的提示。但我也犯了一个错误。我更新了我的问题。谢谢这是工作。我一定错过了。我真的不喜欢symfony2的安全系统。
    http_basic:
        realm: "Secured Demo Area"