Symfony FosUserBundle 正在丢失会话

Symfony2 FosUserBundle is loosing session

我正在使用 FosUserBundle 在我的网站上注册和验证用户。但是我遇到了麻烦,因为用户会话很快就会松动。有时 5 分钟,有时 10 分钟,然后用户再次被重定向到登录表单,导致许多用户离开我的网站。

这是我目前的项目:

composer.json

{"require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.6.*",
        "doctrine/orm": "~2.2,>=2.2.3,<2.5",
        "doctrine/dbal": "<2.5",
        "doctrine/doctrine-bundle": "~1.2",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "symfony/yaml": "2.7.*@dev",
        "symfony/filesystem": "~2.6",
        "sensio/distribution-bundle": "~3.0,>=3.0.12",
        "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
        "incenteev/composer-parameter-handler": "~2.0",
        "friendsofsymfony/user-bundle": "~2.0@dev",
        "friendsofsymfony/jsrouting-bundle": "@stable",
        "knplabs/knp-snappy-bundle": "dev-master",
        "jms/serializer-bundle": "0.13.*"
    },
    "require-dev": {
      "sensio/generator-bundle": "~2.3"
    }
}

config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: "@MoovityUserBundle/Resources/config/services.yml" }
    - { resource: "@MoovityBackendBundle/Resources/config/services.yml" }

framework:
    #esi:             ~
    translator:      { fallback: "%locale%" }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
        cookie_lifetime: 0
        gc_maxlifetime: 14400 
    fragments:       ~
    http_method_override: true
#    translator: ~

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Assetic Configuration
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ MoovityBackendBundle ]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: "%kernel.root_dir%/Resources/java/compiler.jar"
        #yui_css:
        #    jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset: UTF8
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: "%kernel.root_dir%/data/data.db3"
        # path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

fos_user:
    db_driver: orm 
    firewall_name: main
    user_class: Moovity\UserBundle\Entity\User
    registration:
        confirmation:
            enabled: true
            from_email:
                address: noreply@mywebsite.com
                sender_name: mywebsite
            template: MoovityBackendBundle:Mail:mail_fos_user_register_template.html.twig
#            template: FOSUserBundle:Registration:email.html.twig
        form:
            type: moovity_user_registration
    resetting:
        email:
            from_email:
                address:        resetpass@mywensite.com
                sender_name:    My Website Reset Password
            template: FOSUserBundle:Resetting:email.html.twig
        form:
            type: moovity_user_resetting
    service:
        mailer: fos_user.mailer.twig_swift

#fos_rest:
#    routing_loader:
#        default_format: json

security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
#            id: fos_user.user_provider.username
            id: fos_user.user_provider.username_email

    firewalls:
        main:
            pattern: ^/
            form_login:
                login_path: fos_user_registration_register
                check_path: fos_user_security_check
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
#                always_use_default_target_path: true
                # Redirección despues de loguear
                default_target_path: moovity_backend_homepage
            logout:       
                path: fos_user_security_logout
                target: fos_user_registration_register 
#                target: fos_user_security_login

            anonymous:    true
            security: true
            remember_me:
                key:      57361cdee0bb68f4e4b71f06b28fc07e
                lifetime: 6000

我做错了什么?

好的,我注意到 fosuserbundle 正在失去与 Symfony 2.6 的会话,所以我切换到 2.3,现在它似乎可以正常工作了。

非常感谢。

我觉得是翻译的问题。 遇到同样的错误,尝试删除参数中的语言环境并使用 ~

重置它

如果是问题请post