1
votes

I'm working on a symfony3 project, and i'm stuck with a problem,

We are sending emails that are twig based, with a button that has a link to our platform.

Button example

And the open document button link is the following one:

app.example.com/books/bookId/pageId

Which is generated through twig:

url("open_book", { bookId: book_id, pageId: page_id })

And the url is defined on a controller file, with annotations

@Route("/book/{bookId}/{pageId}", name="open_book")

So, the link that user gets on the email, is the original, but with double // before books, like this:

app.example.com//books/bookId/pageId

I'm working on last twig version, and I don't know if it can be symfony issue either, since its only happening on our prod environments (it works on local, yey)

If it helps, our routing.yml

app:
    resource: "@BooksBundle/Controller/"
    type:     annotation
    prefix:   /
    host:     app.%host%

This is only happening with urls that are generated by twig. We are using jms translation and jms i18n bundles also, so I thought maybe its trying to set a null locale betwen / / like:

app.example.com/en/books/bookId/pageId

But instead of en, an empty language maybe.

Any idea to start with?

UPDATE 3/01/18 Hey! Thanks for all answers. It seems that was a problem with symfony configuration at the end...

On file parameters.yml:

router.request_context.scheme: '%env(ROUTER_REQUEST_CONTEXT_SCHEME)%'
router.request_context.host: '%env(ROUTER_REQUEST_CONTEXT_HOST)%'
router.request_context.base_url: '%env(ROUTER_REQUEST_CONTEXT_BASE_URL)%'

Then our value for base_url was /. Seems that was the real problem. Removing / on that param does the trick.

Thanks!!

2
Are the emails generated by a command? - goto
Seems that was a symfony problem. Updated my post with the answer. - Stouter

2 Answers

3
votes

For every route in the controller you are using prefix /:

app:
    resource: "@BooksBundle/Controller/"
    type:     annotation
    prefix:   /
    host:     app.%host%

This means that every route like:

@Route("/book/{bookId}/{pageId}", name="open_book")

Will be prefixed with /. In the end this route path will be //book/{bookId}/{pageId}. Some libraries truncate path values, the other ones not.

So just remove prefix parameter completly or declare route's path without leading slash:

@Route("book/{bookId}/{pageId}", name="open_book")
-2
votes

try to replace this line

  url("open_book", { bookId: book_id, pageId: page_id })

By

  url("open_book", { bookId: book_id, pageId: page_id }) | replace({'//': "/"})

OR

{{ app.request.schemeAndHttpHost }} {{ path("open_book", { bookId: book_id, pageId: page_id }) }}