Reputation: 67
Im using Symfony 4. I want to use Router and mailer in my services. I am including them using Dependency injection.
public function __construct(Swift_Mailer $mailer, EngineInterface $templating, RouterInterface $router)
{
$this->mailer = $mailer;
$this->router = $router;
$this->templating = $templating;
}
I am getting this error:
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?
Any hint to use Mailer, Router services in Symfony 4 ?
Upvotes: 3
Views: 3186
Reputation: 1399
Change the TypeHint and use Interface, the autowire work with interface type hint
try this :
public function __construct(Swift_Mailer $mailer, \Twig_Environment $templating, RouterInterface $router)
Upvotes: 5
Reputation: 4296
I had to composer require symfony/templating
in order to get the Symfony\Bundle\FrameworkBundle\Templating\EngineInterface
service.
Also the following configuration has to be added under framework
:
templating:
enabled: false
engines: ['twig']
Upvotes: 7