I have this code in my controller:
/**
* Displays a form to create a new Bank Account
*
* @Route("/account/new", name="wba_new")
* @Method("GET")
* @Template("BankBundle:BankAccount:new.html.twig")
*/
public function newBankAccountAction() {
$entity = new Account();
$form = $this->createForm(new AccountType(), $entity);
return array('entity' => $entity, 'form' => $form->createView());
}
/**
* Handle bank account creation
*
* @Route("/", name="wba_create")
* @Method("POST")
*/
public function createAction(Request $request) {
$entity = new Account();
$form = $this->createForm(new AccountType(), $entity);
$form->handleRequest($request);
print_r($request);
exit;
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('wba_list'));
}
return array('entity' => $entity, 'form' => $form->createView());
}
When I call /account/new
the form is showed without any problems and action goes to /
but when I send the form I got this error:
The controller must return a response (Array(entity => Object(BankBundle\Entity\AccountType), form => Object(Symfony\Component\Form\FormView)) given).
Why? What is wrong in my code?
UPDATE
I found where the issue was, I have two routes with the same definition in two different controllers:
/**
* Handle bank account creation
*
* @Route("/", name="wba_create")
* @Method("POST")
*/
After fix the problem things works