为什么Symfony不自动连接邮件器、路由器?
我用的是symfony4。我想在我的服务中使用路由器和邮件器。我使用依赖注入将它们包括在内为什么Symfony不自动连接邮件器、路由器?,symfony,symfony4,Symfony,Symfony4,我用的是symfony4。我想在我的服务中使用路由器和邮件器。我使用依赖注入将它们包括在内 public function __construct(Swift_Mailer $mailer, EngineInterface $templating, RouterInterface $router) { $this->mailer = $mailer; $this->router = $router; $this->templating = $templa
public function __construct(Swift_Mailer $mailer, EngineInterface $templating, RouterInterface $router)
{
$this->mailer = $mailer;
$this->router = $router;
$this->templating = $templating;
}
我得到这个错误:
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?
在Symfony 4中是否有使用Mailer、Router服务的提示?请阅读错误消息,开发人员没有出于好玩而编写异常。。。 更改类型提示和使用接口,autowire将使用接口类型提示 试试这个:
public function __construct(Swift_Mailer $mailer, \Twig_Environment $templating, RouterInterface $router)
为了获得
symfony\Bundle\FrameworkBundle\templating\EngineInterface
服务,我必须composer要求symfony/templating
此外,还必须在框架下添加以下配置:
模板:
已启用:false
引擎:['twig']
我已经纠正了这个问题。它为Symfony 3工作。EngineInterface在注入我的服务时出现问题。不过,您的RouterInterface是正确的。请阅读问题。提问者写这篇文章不是为了好玩。很抱歉我总是忍不住向玻璃房子扔石头。在任何情况下,您可能会考虑建议安装和配置模板组件,该组件不再默认发生,然后给出正确的Type提示。仅供参考,我已经为symfony安装了twig和模板。这只是引擎接口造成的问题,这在所有情况下都不起作用,因为engineInterface与Twig\Environment不同,所以它确实bin/console debug:autowiring | grep Engine
列出了您正在寻找的界面?哇,只是在framework
下添加了templating
一节,这对我来说对mesame很有用,但我不得不感谢Trues的lot bro帮我节省了一天+1