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 ?

0

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.