RenderView in Symfony Command usage

TheTom picture TheTom · Jun 29, 2015 · Viewed 11.9k times · Source

How can I use $this->renderView inside a symfony Command (not inside a controller)? I new about the function "renderView" but what do I have to setup to use it wihtin a command?

Thank you in advance an regards

Answer

mykiwi picture mykiwi · Jun 29, 2015

Your command class must extends the ContainerAwareCommand abstract class and then you can do:

$this->getContainer()->get('templating')->render($view, $parameters);

When it comes to commands that extend ContainerAwareCommand the proper way to obtain the container is by getContainer() unlike in controller shortcut.