Jamel Mustapha
Jamel Mustapha

Reputation: 77

Attempted to call an undefined method named "get" of class "MailController"

I want to sent an email with swiftmailer this is my function in my mailController.php

public function newMail(Mail $mail){
        $message = \Swift_Message::newInstance()
            ->setSubject('Accusé de réception')
            ->setFrom('[email protected]')
            ->setTo($mail->getEmail())
            ;

    $this->get('mailer')->send($message);
}

error : Attempted to call an undefined method named "get" of class "UserBundle\Controller\MailController".

Upvotes: 0

Views: 2601

Answers (1)

sensorario
sensorario

Reputation: 21620

Add the use statement atop your controller class and then modify your controller to extend it:

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class YourController extends Controller
{
  // ...
}

That's it! You now have access to methods like $this->get() or $this->render() and many others.

Upvotes: 0

Related Questions