如何获取完整的URL,以将其包含在Symfony2发送的新闻通讯中? [英] How can i get full url to include in newsletter sent with Symfony2?
本文介绍了如何获取完整的URL,以将其包含在Symfony2发送的新闻通讯中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将使用Symfony2定期向许多用户发送新闻通讯.对于那些在使用电子邮件客户端读取邮件时遇到问题的人,我必须添加HTML电子邮件的永久链接.
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 with an email client.
无论如何,假设我以这种方式发送时事通讯:
Anyway, assuming that i'm sending the newsletter this way:
// Assume success and create a new SentMessage to store and get permalink
$sent = new SentMessage();
$sent->setRecipients(/* ... */);
$sent->setSubject(/* ... */);
$sent->setContent(/* ... */);
// Get the slug for the new sent message
$slug = $sent->getSlug(); // Like latest-product-offers-546343
// Construct the full URL
// e.g. http://mydomain.com/newsletter/view/latest-product-offers-546343
// Actually send a new email
$mailer->send(/* .. */);
我如何构建完整的URL(域+控制器+操作+子句)以将其包含在新电子邮件中?
How can i construct the full URL (domain + controller + action + slug) to include it in a new email?
推荐答案
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
$url = $router->generate(
'slug_route_name',
array('slug' => $sent->getSlug()),
UrlGeneratorInterface::ABSOLUTE_URL // This guy right here
);
这篇关于如何获取完整的URL,以将其包含在Symfony2发送的新闻通讯中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文