Sonata Admin:验证后发送电子邮件 [英] Sonata Admin: send email after validation

查看:30
本文介绍了Sonata Admin:验证后发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 symfony2、sonata admin-bundle 和 mongodb,我刚刚制作了一个添加用户的界面,当用户在 Sonataadmin 的 Web 界面上按下 create 时我如何发送电子邮件,我必须覆盖任何类别的 Sonata-Admin?

I am working with symfony2, sonata admin-bundle and mongodb, i just made an interface to add users, how can i send an email when user press create on sonataadmin's web interface, i have to override any class of Sonata-Admin?

//~/UserAdmin.php
      public function create($object)
        {
            parent::create($object);
    
            // send welcome email to new user
            $message = \Swift_Message::newInstance()
                ->setSubject('LOL')
                ->setFrom('no-reply@dummy.com')
                ->setTo('dummy@dummy.com')
                ->setBody('dummy message')
            ;
    
            $this->getConfigurationPool()->getContainer()->get('mailer')->send($message);
        }

我必须使用 $this->getConfigurationPool()->getContainer()-> 来获取容器和邮件程序.

I had to use $this->getConfigurationPool()->getContainer()-> to get the container and the mailer.

推荐答案

您可能想要覆盖管理类中的 create 方法...

You probably want to override the create method in the admin class...

UserAdmin 类:

public function create($object)
{
    parent::create($object);

    // send welcome email to new user
}

这篇关于Sonata Admin:验证后发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆