Symfony2 Templating without request

前端 未结 4 2103
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:54

    The problem arises because you use asset() function in your template.

    By default, asset() relies on Request service to generate urls to your assets (it needs to know what is the base path to you web site or what is the domain name if you use absolute asset urls, for example).

    But when you run your application from command line there is no Request.

    One way to fix this it to explicitely define base urls to your assets in config.yml like this:

    framework:
      templating:
        assets_base_urls: { http: ["http://yoursite.com"], ssl: ["http://yoursite.com"] }
    

    It is important to define both http and ssl, because if you omit one of them asset() will still depend on Request service.

    The (possible) downside is that all urls to assets will now be absolute.

提交回复
热议问题