Symfony2 Templating without request

前端 未结 4 2109
Happy的楠姐
Happy的楠姐 2021-02-15 12:14

I\'m trying to send an email from a ContainerAwareCommand in Symfony2. But I get this exception when the email template is render by:

$body = $this-         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-02-15 12:45

    You need to set the container into the right scope and give it a (fake) request. In most cases this will be enough:

    //before you render template add bellow code
    $this->getContainer()->enterScope('request');
    $this->getContainer()->set('request', new Request(), 'request');
    

    The full story is here. If you want to know the details read this issue on github.

提交回复
热议问题