【发布时间】:2013-08-02 13:51:52
【问题描述】:
我需要在我的视图中创建一个 deleteForm,所以我这样做:
/**
* 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:错误:调用未定义的方法 BankBundle\Controller\WController::createDeleteForm() 在 /var/www/html/src/BankBundle/Controller/WController.php 第 66 行
这个方法有什么问题?我需要使用一些东西来创建表单吗?
解决方案
我找到了解决方案,因为 createDeleteForm() 不是 Symfony2 方法,是我从另一个代码中获取的错误,所以我以这种方式创建函数:
private function createDeleteForm($account_id) {
return $this->createFormBuilder(array('account_id' => $id))->add('account_id', 'hidden')->getForm();
}
瞧,问题消失了!!
【问题讨论】:
标签: symfony symfony-forms symfony-2.3