Php 控制员;SecurityController::loginAction();要求您为“提供”提供一个值$authenticationUtils";论点

Php 控制员;SecurityController::loginAction();要求您为“提供”提供一个值$authenticationUtils";论点,php,symfony,security,authentication,symfony-3.4,Php,Symfony,Security,Authentication,Symfony 3.4,自从从我的项目(symfony3.4)中删除fos用户包后,我正在尝试设置登录表单 我的问题是loginAction需要AuthenticationUtils,但它接收null 我尝试在我的服务中链接它。yml,但它不会移动 任何帮助都将不胜感激 下面是以下文件[SecurityController.php、services.yml、routing.tml] SecurityController.php <?php namespace AppBundle\Controller;

自从从我的项目(symfony3.4)中删除fos用户包后,我正在尝试设置登录表单

我的问题是loginAction需要AuthenticationUtils,但它接收null

我尝试在我的服务中链接它。yml,但它不会移动

任何帮助都将不胜感激

下面是以下文件[SecurityController.php、services.yml、routing.tml]

SecurityController.php

<?php

 namespace AppBundle\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
 
 class SecurityController extends Controller
 {
     public function loginAction(AuthenticationUtils $authenticationUtils)
     {
         // get the login error if there is one
         $error = $authenticationUtils->getLastAuthenticationError();

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

         return $this->render('security/login.html.twig', [
             'last_username' => $lastUsername,
             'error'         => $error,
         ]);
     }
 }
服务.yml

services:      
    AppBundle\Controller\SecurityController:
        class:  'AppBundle\Controller\SecurityController'
        arguments: ['@security.authentication_utils']
希望大家都有想法,因为我已经被困了几天了


提前感谢

如果您要使用自动布线,这会更容易(因为您不需要任何复杂的配置来在操作中使用服务)-但让我们看看为什么这目前不起作用

通过服务配置,您可以为
AppBundle\Controller\SecurityController
的构造函数提供参数。该类在当前状态下不包含任何构造函数,因此该类不包含对
AuthenticationUtils
服务的任何引用

如果您不想使用自动连接,这会有所帮助:向控制器类添加构造函数,Symfony的容器将注入服务

类安全控制器扩展控制器
{
私有$authenticationUtils;
公共函数构造(AuthenticationUtils$AuthenticationUtils){
$this->authenticationUtils=$authenticationUtils;
}
公共函数登录()
{
//如果存在登录错误,则获取登录错误
$error=$this authenticationUtils->getLastAuthenticationError();
//用户最后输入的用户名
$lastUsername=$this authenticationUtils->getLastUsername();
返回$this->render('security/login.html.twig'[
“last_username”=>$lastUsername,
'error'=>$error,
]);
}
}

如果使用自动布线,这会更容易(因为在操作中使用服务不需要任何复杂的配置)-但让我们看看为什么目前无法使用

通过服务配置,您可以为
AppBundle\Controller\SecurityController
的构造函数提供参数。该类在当前状态下不包含任何构造函数,因此该类不包含对
AuthenticationUtils
服务的任何引用

如果您不想使用自动连接,这会有所帮助:向控制器类添加构造函数,Symfony的容器将注入服务

类安全控制器扩展控制器
{
私有$authenticationUtils;
公共函数构造(AuthenticationUtils$AuthenticationUtils){
$this->authenticationUtils=$authenticationUtils;
}
公共函数登录()
{
//如果存在登录错误,则获取登录错误
$error=$this authenticationUtils->getLastAuthenticationError();
//用户最后输入的用户名
$lastUsername=$this authenticationUtils->getLastUsername();
返回$this->render('security/login.html.twig'[
“last_username”=>$lastUsername,
'error'=>$error,
]);
}
}
services:      
    AppBundle\Controller\SecurityController:
        class:  'AppBundle\Controller\SecurityController'
        arguments: ['@security.authentication_utils']