2013-08-02 23 views
-1

我需要在我看來,以創建一個deleteForm所以我這樣做:調用未定義的方法不能創建createDeleteForm

/** 
* Show created bank account 
* 
* @Route("/{account_id}", name="wba_show") 
* @Method("GET") 
*/ 
public function showAction($account_id) { 
     $em = $this->getDoctrine()->getManager(); 
     $entity = $em->getRepository('BankBundle:Account')->find($account_id); 

     if (!$entity) { 
      throw $this->createNotFoundException('Unable to find Account entity.'); 
     } 

     $deleteForm = $this->createDeleteForm($account_id); 
     return array('entity' => $entity, 'delete_form' => $deleteForm->createView()); 
} 

但我得到這個錯誤:

FatalErrorException: Error: Call to undefined method BankBundle\Controller\WController::createDeleteForm() in /var/www/html/src/BankBundle/Controller/WController.php line 66

什麼是錯的這種方法?我需要使用一些東西來創建表單?

解決方案 我找到了解決方案,因爲createDeleteForm()不Symfony2的方法是我的錯誤,從另一個代碼我服用它,所以我用這種方式創建函數:

private function createDeleteForm($account_id) { 
     return $this->createFormBuilder(array('account_id' => $id))->add('account_id', 'hidden')->getForm(); 
} 

瞧問題dissapear !

回答

1

您需要創建一個表單是這樣的:

$this->createForm(new CreateDeleteType()); 

當然,你還需要創建這種形式:

class CreateDeleteType extends AbstractType { 

除此之外,您的錯誤信息是很清楚。您打電話的methodcreateDeleteForm)不存在。請注意,$this是指您當前的控制器上下文而不是窗體上下文。詳細瞭解forms in the official docs

+0

謝謝,我會試試 – Reynier

相關問題