我将使用Symfony2定期向许多用户发送时事通讯。我必须包括HTML电子邮件的永久链接,为那些在阅读电子邮件客户端遇到问题的人。
不管怎样,假设我这样发送时事通讯:
// 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)以将其包含在新电子邮件中?
发布于 2016-03-10 06:26:47
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
https://stackoverflow.com/questions/10621068
复制相似问题