找不到Symfony 2表单句柄请求


Symfony 2 form Handle request not found

我正在symfony 2控制器中制作一个表单。

以下是它的样子:

    $data = date('Y-m-d');
    $time = date('H:i:s');

    $form = $this->createFormBuilder()
        ->add('incident', 'entity', array('class' => 'MainCoreBundle:Incidenttype', 'multiple' => false, 'expanded' => true))
        ->add('date', 'text',array('data'=>$data))
        ->add('time', 'text',array('data'=>$time))
        ->getForm();
   $form->handleRequest($request);

    if ($form->isValid())
        if ($request->getMethod() == "POST") {
            $message = 'Swift_Message::newInstance()
        ->setSubject('SUBJECT')
        ->setFrom('formularz@formularz.pl')
        ->setTo('email@email.com')
        ->setBody(
            $this->renderView(
                'MainAdminBundle:Msg:index.html.twig'));
    $this->get('mailer')->send($message);
    return $this->indexAction($request);
        }

我想制作一个表单,它有:2个输入:-一个当前时间-当前日期的第二个-第三个是来自实体的东西(它将是选择框)

点击后,我想把它发送到邮件中。

我的错误是:Call to undefined method Symfony'Component'Form'Form::handleRequest()

很可能您使用的是2.3 之前的Symfony版本

http://api.symfony.com/2.2/Symfony/Component/Form/Form.html
这个版本的类缺少该方法,尽管它确实使用了bindRequest

http://api.symfony.com/2.3/Symfony/Component/Form/Form.html
方法bindRequest被去除而有利于handleRequest

将composer.json中的symfony/symfony版本切换为~2.5。它与您需要的2.3版本向后兼容。