Sonata Admin: send email after validation

倾然丶 夕夏残阳落幕 提交于 2019-12-10 17:13:36

问题


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?

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.


回答1:


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

UserAdmin class:

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

    // send welcome email to new user
}


来源:https://stackoverflow.com/questions/21913356/sonata-admin-send-email-after-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!