我一直在尝试按照 Symfony 书中的说明实现一个简单的表单登录,但我在登录时卡住了。 每当我尝试登录时,我都会收到从 AbstractAuthenticationListener::handle 抛出的“此身份验证方法需要 session ”错误。 我搜索了 Symfony 的书和食谱以及谷歌,但没有找到答案,甚至没有找到一些相关问题。
这是我误解了书中的内容还是我的服务器配置错误?
如果您需要代码提取,请不要介意询问...
安全.yml
security:
encoders:
Common\Bundle\UserBundle\Entity\User:
algorithm: bcrypt
cost: 10
providers:
main:
entity: { class: CommonUserBundle:User }
firewalls:
main:
pattern: ^/
provider: main
anonymous: ~
simple_form:
authenticator: simple_authenticator
login_path: /Connexion
check_path: /Connexion/verifier
logout:
path: /Deconnexion
target: /
remember_me:
key: "%secret%"
lifetime: 2592000
path: /
domain: ~
配置.yml
framework:
secret: "%secret%"
fragments: { path: /_fragment }
router:
resource: "%kernel.root_dir%/config/routing.yml"
validation:
enable_annotations: true
templating:
engines: ['twig']
default_locale: "%locale%"
http_method_override: true
最佳答案
您需要启用 PHP session 来保持用户登录。您的 config.yml
文件看起来未启用,在 framework
根级别添加一个 session
部分:
这是默认配置:
framework:
# ...
session: ~
查看官方文档以了解如何配置 session 存储:http://symfony.com/doc/current/reference/configuration/framework.html#session
关于php - Symfony2 "This authentication method requires a session"登录检查错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25248490/