4
votes

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('[email protected]')
                ->setTo('[email protected]')
                ->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
What exactly do you want to add as functionality? Send the creator an email or sent to the user you created an email that he has been added?Geert Wille
send to the user you created an emailJorge
Thanks for the answer, but you should not answer the question as a questionBraian Mellor

1 Answers

3
votes

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
}