我有一个简单的登录表单:
public function loginAction(Request $request)
{
$authenticationUtils = $this->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render(
'users/login.html.twig',
[
'page' => 'login',
'last_username' => $lastUsername,
'error' => $error,
]
);
}
Run Code Online (Sandbox Code Playgroud)
security.yml:
secured_area:
form_login:
provider: user_db_provider
login_path: /login
check_path: /login
csrf_token_generator: security.csrf.token_manager
Run Code Online (Sandbox Code Playgroud)
我正在尝试设置用户的上次登录时间.
难道我真的要创建一个新的监听器,并写一整类,像这样的回答,只为这单指令:$user->setLastLogin(new \DateTime());?或者是否有更简单的东西,比如把它放在控制器中?
| 归档时间: |
|
| 查看次数: |
3641 次 |
| 最近记录: |