我已经创建了自定义事件,例如当用户被生成时,事件调度程序将触发该事件。
我正在关注本教程。我想知道他class CommentListener
如何访问实体管理器,因为我想在数据库中保留一些东西。
类是这样的:
class CommentListener
{
protected $mailer;
public function __construct(Swift_Mailer $mailer)
{
$this->mailer = $mailer;
}
public function onCommentEvent(CommentEvent $event)
{
$post = $event->getPost();
$comment = $event->getComment();
foreach ($post->getSubscribers() as $subscriber) {
$message = Swift_Message::newInstance()
->setSubject('New comment posted on ' . $post->getTitle())
->setFrom('send@example.com')
->setTo($subscriber->getEmail())
->setBody("Hey, somebody left a new comment on a post you're subscribed to! It says: " . $comment->getBody())
;
$this->mailer->send($message);
}
}
}
那么我怎样才能访问里面的实体管理器onCommentEvent
呢?