简体   繁体   English

试图调用类“ MailController”的未定义方法“ get”

[英]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 我想用swiftmailer发送电子邮件,这是我的mailController.php中的函数

public function newMail(Mail $mail){
        $message = \Swift_Message::newInstance()
            ->setSubject('Accusé de réception')
            ->setFrom('hela.mejri@esprit.tn')
            ->setTo($mail->getEmail())
            ;

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

error : Attempted to call an undefined method named "get" of class "UserBundle\\Controller\\MailController". 错误:试图调用类“ UserBundle \\ Controller \\ MailController”的名为“ get”的未定义方法。

Add the use statement atop your controller class and then modify your controller to extend it: 在您的控制器类上添加use语句,然后修改您的控制器以对其进行扩展:

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. 现在,您可以访问$this->get()$this->render()等方法。

暂无
暂无

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

相关问题 试图调用一个未定义的名为“查询”的类的方法 - Attempted to call an undefined method named “query” of class 尝试调用类的名为“ getEntityManager”的未定义方法 - Attempted to call an undefined method named “getEntityManager” of class 尝试调用类的名为“ renderView”的未定义方法 - Attempted to call an undefined method named “renderView” of class 尝试调用类“ DOMElement”的未定义方法“ filter” - Attempted to call an undefined method named “filter” of class “DOMElement” 尝试调用类“ Knp \\ Menu \\ MenuItem”的名为“ setCurrentUri”的未定义方法 - Attempted to call an undefined method named “setCurrentUri” of class “Knp\Menu\MenuItem” PHP 7.2.7:尝试调用类“ZipArchive”的名为“setEncryptionName”的未定义方法 - PHP 7.2.7: Attempted to call an undefined method named “setEncryptionName” of class “ZipArchive” 尝试调用类“ Zend \\ Http \\ Client”中名为“ request”的未定义方法 - Attempted to call an undefined method named “request” of class “Zend\Http\Client” 尝试调用类“ App \\ Twig \\ AppExtension”中名为“ getDoctrine”的未定义方法 - Attempted to call an undefined method named “getDoctrine” of class “App\Twig\AppExtension” 尝试调用类“ Swift_Mailer”的名为“ getContext”的未定义方法 - Attempted to call an undefined method named “getContext” of class “Swift_Mailer” 尝试调用类“ AppBundle \\ Controller \\ DefaultController”的未定义方法“ getRequest” - Attempted to call an undefined method named “getRequest” of class “AppBundle\Controller\DefaultController”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM