Answer the question
In order to leave comments, you need to log in
How to get a renderView in a service that doesn't inherit from the Controller class?
I have a service in which I need to use the renderView() of the Controller class. What do I need to inject to use this method in my service? preferably with an example, thanks)
Answer the question
In order to leave comments, you need to log in
class SomeService
/**
* @var \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface
*/
private $templating;
public function __construct(EngineInterface $templating)
{
$this->templating = $templating;
}
public function doSome()
{
$template = $this->templating->render('AppBundle::foo.html.twig', array(
'foo' => 'bar'
));
}
services:
app.service.foo:
class: %app.service.foo.class%
arguments:
- @templating
If this is necessary, then something is wrong in the application architecture.
If you really need it, the controller becomes a service and is injected through DIC
I would stop only on the first suggestion of Alex T.
> If this is necessary, then something is wrong in the application architecture.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question