2014-08-31 68 views
0

當我嘗試更新我的entites之一,我得到這個異常:更新實體表單

UndefinedMethodException:試圖調用方法「bindRequest」階級「的Symfony \分量\表\表」 /應用程序/MAMP/htdocs/Seotool/src/Seotool/MainBundle/Controller/TaskController.php線路64

編輯操作:

/** 
@Route(
*  path = "/tasks/edit/{id}", 
*  name = "edit_task" 
*) 
* @Template() 
*/ 
public function edit_taskAction($id, Request $request) 
{ 

    $request = $this->get('request'); 

    if (is_null($id)) { 
     $postData = $request->get('task'); 
     $id = $postData['id']; 
    } 

    $em = $this->getDoctrine()->getManager(); 
    $task = $em->getRepository('SeotoolMainBundle:Task')->find($id); 
    $form = $this->createForm(new TaskType(), $task); 

    if ($request->getMethod() == 'POST') { 
     $form->bindRequest($request); 

     if ($form->isValid()) { 
      // perform some action, such as save the object to the database 
      $em->flush(); 

      return $this->redirect($this->generateUrl('taskmanager')); 
     } 
    } 

    return array('form' => $form->createView()); 

} 

這有什麼錯我的代碼?

回答

1

因爲沒有方法bindRequest。這個例外很明顯。如果你檢查官方API,我想你想用handleRequest

+0

謝謝,這對我有用! – Marvin 2014-08-31 14:23:09