我試圖通過在Symfony 3中的SwiftMailer發送一封電子郵件。我正在閱讀該教程:http://tutorial.symblog.co.uk/docs/validators-and-forms.html#sending-the-email,並且我遇到了「在控制器中創建表單」 : 「試圖調用名爲一個未定義的方法 」「 一流的 」調用getRequest的appbundle \控制器\ DefaultController試圖調用類的名爲「getRequest」的未定義方法。 Sendind電子郵件在SwiftMailer Symfony
這是我的contactAction()中的src /的appbundle/DeffaultController「。」:
/**
* @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()
));
}
請幫助!
你的文件和類名相同,並且在命名空間設置是否正確?你的課是否擴展了根控制器,讓你可以訪問這些方法? – Psyco430404