我正在尝试制作一个捆绑包(Symfony 4)来管理我们所有项目的用户,但是我遇到了问题。
无法自动装配“ App \ Aroban \ Bundle \ UtilisateurBundle \ Controller \ SecurityController :: login()”的参数$ authenticationUtils:它引用类“ Symfony \ Component \ Security \ Http \ Authentication \ AuthenticationUtils”,但不存在此类服务。 >
我不明白为什么没有注入服务...
在项目的composer.json中,有“ symfony / security-bundle”:“ 4.3。*”
在捆绑包中:
SecurityController.php
<?php namespace App\Aroban\Bundle\UtilisateurBundle\Controller; use App\Aroban\Bundle\UtilisateurBundle\Entity\Utilisateur; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Swift_Mailer; class SecurityController extends AbstractController { public function login(AuthenticationUtils $authenticationUtils): Response { $error = $authenticationUtils->getLastAuthenticationError(); $lastUsername = $authenticationUtils->getLastUsername(); return $this->render('@Utilisateur/security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); } ....... }
Configuration.php
<?php namespace App\Aroban\Bundle\UtilisateurBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('utilisateur'); $rootNode = $treeBuilder->getRootNode(); return $treeBuilder; } }
UtilisateurExtension.php
<?php namespace App\Aroban\Bundle\UtilisateurBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Loader; class UtilisateurExtension extends Extension { /** * {@inheritdoc} */ public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yaml'); } }
services.yaml(捆绑销售)
services: _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. public: false # Allows optimizing the container by removing unused services; this also means App\Aroban\Bundle\UtilisateurBundle\: resource: '../../*' exclude: '../../{Entity,Migrations,Tests,Kernel.php}' App\Aroban\Bundle\UtilisateurBundle\Controller\: resource: '../../Controller/*' tags: ['controller.service_arguments']
执行命令时
php bin /控制台debug:container | grep安全性
我看不到该服务...
Symfony \ Component \ Security \ Csrf \ CsrfTokenManagerInterface别名为“ security.csrf.token_manager”Symfony \ Component \ Security \ Csrf \ TokenGenerator \ TokenGeneratorInterface别名“ security.csrf.token_generator”Symfony \ Component \ Security \ Csrf \ TokenStorage \ TokenStorageInterface的别名“ security.csrf.token_storage”doctrine.orm.security.user.provider Symfony \ Bridge \ Doctrine \ Security \ User \ EntityUserProvidermaker.security_config_updater Symfony \ Bundle \ MakerBundle \ Security \ SecurityConfigUpdatersecurity.csrf.token_generator的Symfony \分量\安全\ CSRF \ TokenGenerator \ UriSafeTokenGeneratorsecurity.csrf.token_manager Symfony \ Component \ Security \ Csrf \ CsrfTokenManagersecurity.csrf.token_storage Symfony \ Component \ Security \ Csrf \ TokenStorage \ SessionTokenStoragetwig.extension.security_csrf Symfony \ Bridge \ Twig \ Extension \ CsrfExtensiontwig.runtime.security_csrf Symfony \ Bridge \ Twig \ Extension \ CsrfRuntime//要搜索特定服务,请使用搜索词重新运行此命令。 (例如debug:container//日志)
感谢您的帮助!
我正在尝试制作一个Bundle(Symfony 4)来管理我们所有项目的用户,但遇到了问题。无法自动装配“ App \ Aroban \ Bundle \ UtilisateurBundle \ ...”的自变量$ authenticationUtils。>
您之后尝试composer install
吗?
这将安装您在composer.json中指定的依赖项