【发布时间】:2014-07-30 20:45:49
【问题描述】:
我正在尝试填写联系表格然后发送。但是,当我填写表格并单击发送时,我有这个例外:
UndefinedMethodException: Attempted to call method "bindRequest" on class "Symfony\Component\Form\Form" in /symfony/src/tuto/WelcomeBundle/Form/Handler/ContactHandler.php line 47.
这是ContactHandler.php的内容:
命名空间教程\WelcomeBundle\Form\Handler;
使用 Symfony\Component\Form\Form; 使用 Symfony\Component\HttpFoundation\Request;
/**
* The ContactHandler.
* Use for manage your form submitions
*
* @author Abderrahim
*/
class ContactHandler
{
protected $request;
protected $form;
protected $mailer;
/**
* Initialize the handler with the form and the request
*
* @param Form $form
* @param Request $request
* @param $mailer
*
*/
public function __construct(Form $form, Request $request, $mailer)
{
$this->form = $form;
$this->request = $request;
$this->mailer = $mailer;
}
/**
* Process form
*
* @return boolean
*/
public function process()
{
// Check the method
if ('POST' == $this->request->getMethod())
{
// Bind value with form
$this->form->bindRequest($this->request);
$data = $this->form->getData();
$this->onSuccess($data);
return true;
}
return false;
}
/**
* Send mail on success
*
* @param array $data
*
*/
protected function onSuccess($data)
{
$message = \Swift_Message::newInstance()
->setContentType('text/html')
->setSubject($data['subject'])
->setFrom($data['email'])
->setTo('xxxx@gmail.com')
->setBody($data['content']);
$this->mailer->send($message);
}
}
你能给我任何帮助吗!!
【问题讨论】:
-
你试过
bind吗? -
谢谢它现在可以使用了!!
-
太好了,我会添加它作为答案。