为什么Symfony不自动为邮件,路由器布线?

Sur*_*ain 3 symfony symfony4

我正在使用Symfony4。我想在服务中使用路由器和邮件程序。我使用依赖注入将它们包括在内。

public function __construct(Swift_Mailer $mailer, EngineInterface $templating, RouterInterface $router)
{
    $this->mailer = $mailer;
    $this->router = $router;
    $this->templating = $templating;
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

argument "$templating" of method "__construct()" references interface "Symfony\Component\Templating\EngineInterface" but no such service exists. It cannot be auto-registered because it is from a different root namespace. Did you create a class that implements this interface?
Run Code Online (Sandbox Code Playgroud)

是否有任何在Symfony 4中使用Mailer,Router服务的提示?

Sma*_*ïne 5

更改 TypeHint 并使用 Interface,自动装配与接口类型提示一起使用

尝试这个 :

public function __construct(Swift_Mailer $mailer, \Twig_Environment $templating, RouterInterface $router)
Run Code Online (Sandbox Code Playgroud)


Man*_*tas 5

我必须composer require symfony/templating为了获得Symfony\Bundle\FrameworkBundle\Templating\EngineInterface服务。

另外,还必须在下面添加以下配置framework

templating: enabled: false engines: ['twig']

  • 对我来说也是如此,但我必须能够做到这一点 (2认同)