我正在使用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服务的提示?
更改 TypeHint 并使用 Interface,自动装配与接口类型提示一起使用
尝试这个 :
public function __construct(Swift_Mailer $mailer, \Twig_Environment $templating, RouterInterface $router)
Run Code Online (Sandbox Code Playgroud)
我必须composer require symfony/templating为了获得Symfony\Bundle\FrameworkBundle\Templating\EngineInterface服务。
另外,还必须在下面添加以下配置framework:
templating:
enabled: false
engines: ['twig']
| 归档时间: |
|
| 查看次数: |
1402 次 |
| 最近记录: |