Symfony 4 AuthenticationUtils

Eri*_*rik 5 php authentication service symfony4

我正在尝试根据symfony.com的教程创建一个使用symfony 4的用户登录.

我使用了以下代码的基本services.yaml文件.

https://symfony.com/doc/current/security/form_login_setup.html

public function loginAction(Request $request, \Twig_Environment $twigRenderer,AuthenticationUtils $authUtils)
{

    // get the login error if there is one
    $error = $authUtils->getLastAuthenticationError();

    // last username entered by the user
    $lastUsername = $authUtils->getLastUsername();


    return new response($twigRenderer->render('security/login.html.twig', array(
        'last_username' => $lastUsername,
        'error'         => $error,
        )
    ));
}
Run Code Online (Sandbox Code Playgroud)

Errror:

控制器"App\Controller\SecurityController :: loginAction()"要求您为"$ authUtils"参数提供值.参数可以为空,并且没有提供空值,没有提供默认值,或者因为在此之后存在非可选参数.

我不知道如何解决这个问题.有人有建议吗?

Guh*_*uhh 1

我遇到了同样的问题..尝试运行命令:

composer require security
Run Code Online (Sandbox Code Playgroud)