【发布时间】:2017-04-20 06:08:02
【问题描述】:
我正在尝试通过 Symfony 3 中的 SwiftMailer 发送电子邮件。我正在阅读该教程:http://tutorial.symblog.co.uk/docs/validators-and-forms.html#sending-the-email,我在“在控制器中创建表单”中遇到了问题:“尝试调用“AppBundle\Controller\DefaultController”类的名为“getRequest”的未定义方法。”
这是我在 src/AppBundle/DeffaultController 中的 contactAction():
/**
* @Route("/contact"), name="cont")
*/
public function contactAction()
{
$enquiry = new Enquiry();
$form = $this->createForm(EnquiryType::class, $enquiry);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
// Perform some action, such as sending an email
// Redirect - This is important to prevent users re-posting
// the form if they refresh the page
return $this->redirect($this->generateUrl('app_default_contact'));
}
}
return $this->render(':default:contact.html.twig', array(
'form' => $form->createView()
));
}
请帮忙!
【问题讨论】:
-
你的文件名和类名是否相同,命名空间设置是否正确?你的类是否扩展了根控制器,让你可以访问这些方法?
标签: php email symfony swiftmailer