3

In my Symfony2 project, I send email with a link to connect to my website, like

<a href="{{ url('login') }}">LOGIN</a>

When I use this template in a controller, the link is good.

<a href="https://example.com/login">LOGIN</a>

But if I use this template for my mail in a ContainerAwareCommand with a cron, it looks like

<a href="http://localhost/login">LOGIN</a>

It's not good. How am I suppose to do to make it work ?

Veve
  • 6,643
  • 5
  • 39
  • 58
eluus
  • 213
  • 1
  • 13

1 Answers1

9

You should Configure the Request Context Globally, as described in the doc How to Generate URLs from the Console:

you can redefine the parameters it uses as default values to change the default host (localhost) and scheme (http). You can also configure the base path if Symfony is not running in the root directory.

Note that this does not impact URLs generated via normal web requests, since those will override the defaults.

# app/config/parameters.yml
parameters:
    router.request_context.host: example.org
    router.request_context.scheme: https
    router.request_context.base_url: my/path

hope this help

Matteo
  • 37,680
  • 11
  • 100
  • 115