我想获取保存在会话中的 last_username 以在登录表单中使用它,但 $session->get(SecurityContext::LAST_USERNAME) 始终为空
这是我的代码:
配置.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_proxies: ['127.0.0.1']
session:
cookie_lifetime: 31536000
fragments: ~
登录动作:
public function loginAction(Request $request)
{
$session = $request->getSession();
ld( $session->get(SecurityContext::LAST_USERNAME));
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(
SecurityContext::AUTHENTICATION_ERROR
);
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
return array(
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error
);
}
什么时候出现错误?
谢谢
问候