M
M
Messi2017-04-05 13:43:13
symfony
Messi, 2017-04-05 13:43:13

How to get a link to the main page?

In the controller did

$homePage = Container::getRouter()->getContext()->getScheme() . '://' . Container::getRouter()->getContext()->getHost() . '/';

Will be substituted http or https + host.
How can this line be made simpler?
Or is this a normal option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bears, 2017-04-05
@FitTech

$homepage = $this->generateUrl('homepage', [], \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL);

Instead of 'homepage', of course, the name of the homepage route.
But it can also be obtained from Request:
$request->getSchemeAndHttpHost();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question