简体   繁体   English

Sonata Admin:验证后发送电子邮件

[英]Sonata Admin: send email after validation

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? 我正在使用symfony2,sonata admin-bundle和mongodb,我只是创建了一个添加用户的界面,当用户在sonataadmin的web界面上按下create时如何发送电子邮件,我必须覆盖任何类的Sonata-Admin?

UPDATE UPDATE

//~/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);
        }

I had to use $this->getConfigurationPool()->getContainer()-> to get the container and the mailer. 我不得不使用$this->getConfigurationPool()->getContainer()->来获取容器和邮件程序。

You probably want to override the create method in the admin class... 您可能想要覆盖admin类中的create方法...

UserAdmin class: UserAdmin类:

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

    // send welcome email to new user
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM