RenderView in Symfony Command usage

后端 未结 3 2144
迷失自我
迷失自我 2021-02-20 08:52

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 comman

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-20 09:30

    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.

提交回复
热议问题