首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >怎样才能让完整的网址包含在随Symfony2发送的时事通讯中?

怎样才能让完整的网址包含在随Symfony2发送的时事通讯中?
EN

Stack Overflow用户
提问于 2012-05-16 22:48:56
回答 1查看 15.8K关注 0票数 22

我将使用Symfony2定期向许多用户发送时事通讯。我必须包括HTML电子邮件的永久链接,为那些在阅读电子邮件客户端遇到问题的人。

不管怎样,假设我这样发送时事通讯:

代码语言:javascript
复制
// 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 (域+控制器+操作+ slug)以将其包含在新电子邮件中?

EN

回答 1

Stack Overflow用户

发布于 2016-03-10 06:26:47

Symfony 3更新:

代码语言:javascript
复制
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
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10621068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档