2014-09-10 36 views
1

我在symfony 2控制器中創建表單。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('[email protected]') 
     ->setTo('[email protected]') 
     ->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()

+0

在處理它之前得到'echo get_class($ form);'的結果。 – Flosculus 2014-09-10 11:23:47

+0

Symfony \ Component \ Form \ Form – Cre3k 2014-09-10 11:26:13

+0

您正在使用哪個版本的Symfony? 2.2? – Flosculus 2014-09-10 11:28:10

回答

4

機會是您正在使用一個版本的Symfony的2.3之前,

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這是您需要的版本。

+0

bindRequest有幫助。非常感謝 – Cre3k 2014-09-15 09:42:30