我的控制器中有这段代码:
/**
* 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());
}
当我打电话时/account/new
,表格显示没有任何问题,/
但当我发送表格时,我收到了这个错误:
控制器必须返回一个响应(Array(entity => Object(BankBundle\Entity\AccountType), form => Object(Symfony\Component\Form\FormView)) 给定)。
为什么?我的代码有什么问题?
更新
我发现问题出在哪里,我在两个不同的控制器中有两条具有相同定义的路由:
/**
* Handle bank account creation
*
* @Route("/", name="wba_create")
* @Method("POST")
*/
解决问题后一切正常