How can i get full url to include in newsletter sent with Symfony2?

前端 未结 3 1146
走了就别回头了
走了就别回头了 2020-12-29 23:56

I\'m going to use Symfony2 to sent periodically a newsletter to many users. I\'ve to include a permalink to the HTML email for those who experience problems in reading them

相关标签:
3条回答
  • 2020-12-30 00:26

    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
    
    0 讨论(0)
  • 2020-12-30 00:35

    TWIG

    If this is within a twig template, use url('your route') instead of path('your route') to get the absolute URL.

    0 讨论(0)
  • 2020-12-30 00:44

    With the router, of course

    By default, the router will generate relative URLs (e.g. /blog). To generate an absolute URL, simply pass true to the third argument of the generate() 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
    );
    
    0 讨论(0)
提交回复
热议问题