-1

I need to create a deleteForm in my view so I do this:

/**
 * 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());
}

But I get this error:

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

What is wrong in this method? I need to use something to create the form?

Solution I found the solution since createDeleteForm() isn't Symfony2 method and was my mistake taking it from another code I have so I create the function in this way:

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

And voila problem dissapear!!

Reynier
  • 2,420
  • 11
  • 51
  • 91

1 Answers1

1

You need to create a form like this:

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

Of course you also need to create this form:

class CreateDeleteType extends AbstractType {

Other than that your error message is quite clear. The method you are calling (createDeleteForm) does not exist. Be aware that $this refers to your current controller context not the form context. Read more about forms in the official docs.

ferdynator
  • 6,245
  • 3
  • 27
  • 56