Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
服务autowire don';t与Symfony 4一起工作_Symfony_Symfony4 - Fatal编程技术网

服务autowire don';t与Symfony 4一起工作

服务autowire don';t与Symfony 4一起工作,symfony,symfony4,Symfony,Symfony4,我尝试从Symfony 3.4转换到Symfony 4.1,但autowire有问题。我已经安装了symfony/swiftmailer捆绑包,在事件订阅服务器中,我有: public function __construct(\Swift_Mailer $mailer, EngineInterface $templating, EntityManagerInterface $em, $senderMail, $senderName) { $this->mailer = $mail

我尝试从Symfony 3.4转换到Symfony 4.1,但autowire有问题。我已经安装了symfony/swiftmailer捆绑包,在事件订阅服务器中,我有:

public function __construct(\Swift_Mailer $mailer, EngineInterface $templating, EntityManagerInterface $em, $senderMail, $senderName)
{
    $this->mailer = $mailer;
    $this->templating = $templating;
    $this->em = $em;
    $this->senderMail = $senderMail;
    $this->senderName = $senderName;
}
在service.yaml中:

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: 'en'

services:
    # default configuration for services in *this* file
    _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
                        # fetching services directly from the container via $container->get() won't work.
                        # The best practice is to be explicit about your dependencies anyway.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
    resource: '../src/*'
    exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
    resource: '../src/Controller'
    tags: ['controller.service_arguments']

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones


# Twig
    twig.extension.text:
       class: Twig_Extensions_Extension_Text
       tags:
       - { name: twig.extension }

# Listeners
    App\EventListener\ContactNotificationSubscriber:
    $senderMail: '%env(MAILER_SENDER_ADDRESS)%'
    $senderName: '%env(MAILER_SENDER_NAME)%'
但我有一个错误:

无法自动连线服务“App\EventListener\ContactNotificationSubscriber”:方法“\uu construct()”的参数“$mailer”引用类“Swift\u mailer”,但不存在此类服务

我不明白为什么。。。该组件存在,使用PhpStorm,我可以单击\Swift\u Mailer查看该类,但Symfony总是向我返回一个错误


如果有人知道原因:-)非常感谢

我也有同样的问题。就我而言,bundle没有包含在
bundles.php
中。在
bundles.php中添加以下内容为我解决了这个问题:

Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],

运行“bin/console debug:container Swift\u Mailer”并确认您有一个名为Swift\u Mailer的服务。并验证您的senderMail/Name属性是否正确缩进。如果我不得不猜测,我会说您没有更新swift邮件包。因此,该服务不存在。我已经找到了v3.2.2I,但也许有一种方法可以自动完成,我使用了symfony命令:
composer创建项目symfony/website skeleton my_project
安装一个新项目,然后,我将整个composer.json文件复制/粘贴到我的旧项目中,然后使用
composer update
composer require
用于我在项目中使用的包。事实上,它安装了symfony/swiftmailer包,但没有安装其依赖项。。。。有办法吗?我已经做了
composer删除symfony/swiftmailer\u bundle
然后
composer需要symfony/swiftmailer\u bundle
。但我对所有其他依赖性都有疑问……这可能很棘手。我成功地创建了一个新项目,安装了所有其他依赖项,然后将composer.json复制回现有项目。然后解决问题。检查别名可以解决此问题。