0

I've come across a problem which is explained well in this GitHub issue https://github.com/symfony/symfony/issues/4514

Short version: It's not possible to render asset URLs from the CLI because there is no Request object. The Github issue is closed. I suppose it is not a bug, but it is stopping my system from rendering HTML emails in cronjobs.

So my question:

Is there a way to allow templates to use {{ asset() }} from within a Symfony Command where there is no server request scope?

Some kind of dummy request sounds like it could work, but I have no idea how to get into that particular black box.

Tim
  • 8,036
  • 2
  • 36
  • 52

1 Answers1

1

Like explained in how to send emails in console command

do like this

$context = $this->getContainer()->get('router')->getContext();
$context->setHost('example.com');
$context->setScheme('https');
julien rollin
  • 1,607
  • 1
  • 12
  • 17
  • That's great thank. It fixes the URL generation issue,m but it does't fix the `{{asset}}` problem though. As the Github issue states. the assets helper doesn't work when there's no request scope. – Tim Feb 05 '13 at 14:35
  • exact... you have no choice that generating url from router or building your own url with custom parameters stored in your container, and use them in your template – julien rollin Feb 05 '13 at 15:33
  • this is unfortunate. I've worked around it using a simple base href parameter in my templates. I may try later on to access `assets_version` manually so I can use my CDN. It'll do for now. Cheers. – Tim Feb 05 '13 at 15:38