Home > Net >  Symfony upgrade from 4.1 to 4.4 authenticationutils servicelocator
Symfony upgrade from 4.1 to 4.4 authenticationutils servicelocator

Time:10-13

I am trying upgrade Symfony application from 4.1 to 4.4 and I have error in authentication in SecurityController I have

public function loginAction (Request $request)
    {
        /* var AuthenticationUtils $authUtils */
        $authUtils= $this->get('security.authentication_utils');
        
        // get the login error if there is one
        $error = $authUtils->getLastAuthenticationError();
        
        // last username entered by the user
        $lastUsername = $authUtils->getLastUsername();

        return $this->render('admin/user/login.html.twig', array(
            'error'         => $error,
            'last_username' => $lastUsername,
        ));
    }

but after upgrade I have this error enter image description here

how I may solve this error?

CodePudding user response:

..as mentioned by @dbrunmann

public function loginAction (Request $request, AuthenticationUtils $authUtils)
    {        
        // get the login error if there is one
        $error = $authUtils->getLastAuthenticationError();
        
        // last username entered by the user
        $lastUsername = $authUtils->getLastUsername();

        return $this->render('admin/user/login.html.twig', array(
            'error'         => $error,
            'last_username' => $lastUsername,
        ));
    }

Use php bon\console debug:autowiring <some_service_name> - to find out which typhint to use to get the right service

E.g. php bin\console debug:autowiring utils will give you

enter image description here

  • Related