[英]Symfony2, Sonata, UserBundle : Send email when user is enable on update
I would like to be able to send an email to the user when the admin enable the user in Sonata admin panel. 当管理员在Sonata管理面板中启用用户后,我希望能够向用户发送电子邮件。
I have to idea which file i should override or extend. 我必须知道我应该覆盖或扩展哪个文件。
I suppose it is similar to this subject or this stack-overflow subject : 我想它类似于这个主题或这个堆栈溢出主题 :
/**
* {@inheritdoc}
*/
public function create($object)
{
parent::create($object);
// send welcome email to new user
}
I found the create function in the admin bundle but i suppose it would not be overridden only for the UserBundle. 我在管理包中找到了create函数,但我想它不会仅对UserBundle覆盖。 If it is indeed the way to go, how could i specify for the UserBundle only? 如果确实要走,我该如何只为UserBundle指定?
For the information I can't find any create or update function in UserBundle. 有关信息,我在UserBundle中找不到任何创建或更新功能。 Only in the AdminBundle. 仅在AdminBundle中。
I will relate to contract event from my gist: https://gist.github.com/webdevilopers/4eea317ade72a119a72e Adapt it to your needs. 我将根据我的要点处理合同事件: https: //gist.github.com/webdevilopers/4eea317ade72a119a72e使其适应您的需求。 Guess you can simply rename "Contract" to "User". 猜猜您可以简单地将“合同”重命名为“用户”。
Then add the event somewhere in your admin class: 然后将事件添加到您的管理类中的某个位置:
$event = new ContractEvent($contract);
$dispatcher = $this->get('event_dispatcher');
$dispatcher->dispatch(
ContractEvents::CONTRACT_CREATED,
$event
);
See the gist for details how to inject SwiftMailer. 请参阅要点,以获取有关如何注入SwiftMailer的详细信息。
Instead of creating your own event you can choose from the events Sonata Admin offers you: Admin's documentation - Reference - Events (master) 除了创建自己的事件,您还可以从Sonata Admin提供的事件中进行选择: Admin的文档-参考-事件(主)
Pick up the one that suits your needs. 挑选一个适合您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.