How can i get full url to include in newsletter sent with Symfony2?
With the router, of course
By default, the router will generate relative URLs (e.g.
/blog
). To generate an absolute URL, simply passtrue
to the third argument of thegenerate()
method:
Perhaps your code might look like this
Symfony2
$url = $router->generate( 'slug_route_name', array('slug' => $sent->getSlug()), true // This guy right here);
Symfony3
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;$url = $router->generate( 'slug_route_name', array('slug' => $sent->getSlug()), UrlGeneratorInterface::ABSOLUTE_URL // This guy right here);
Update with Symfony 3:
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;$this->generateUrl('blog_show', array('slug' => 'my-blog-post'), UrlGeneratorInterface::ABSOLUTE_URL);// http://www.example.com/blog/my-blog-post
TWIG
If this is within a twig template, use url('your route')
instead of path('your route')
to get the absolute URL.