2013-08-05 7 views
0

내가 내 컨트롤러에서이 코드가 실행되지 않습니다 : 내가 /account/new를 호출 할 때컨트롤러는 응답을 반환해야 작업이

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

양식이 아무 문제없이 보여 주었다과 행동이 /로 이동되지만를 나는를 보낼 때 양식이 오류가 발생했습니다 :

The controller must return a response (Array(entity => Object(BankBundle\Entity\AccountType), form => Object(Symfony\Component\Form\FormView)) given).

왜? 내 코드에서 무엇이 잘못 되었습니까? 문제 상황을 해결하는 것은 읽기 후

+1

어떤 종류의'Response' 객체를 반환 할 컨트롤러 액션이 아닌가? –

+0

@JoachimIsaksson 항상 그렇지는 않습니다. 내 에디션을 참조하십시오. – Reynier

+1

@JoachimIsaksson이 옳습니다. 'createAction()'함수 위에'@ Template' 주석을 잊어 버렸습니다. – cheesemacfly

답변

0

를 작동 한 후

/** 
* Handle bank account creation 
* 
* @Route("/", name="wba_create") 
* @Method("POST") 
*/ 

: 문제가 어디에

UPDATE

가 나는 두 개의 서로 다른 컨트롤러에서 동일한 정의 두 개의 경로를 가지고, 발견 코드가 다시 완성되고 내 실수가있는 곳을 찾으십시오. 마침내 찾았습니다. 나는 두 개의 컨트롤러했다 : AccountController.phpTestController.php을 같은이 기능에서와 같은 경로 (난 그냥 AccountController.phpTestController.php에 복사하기 때문에 내 실수를) 모두에 내가 정의했다 : 그 이유

/** 
* Handle bank account creation 
* 
* @Route("/", name="wba_create") 
* @Method("POST") 
*/ 
public function createAction(Request $request) { 
    ... 
} 

을, 나는 힘든이었다 이유 Symfony가 wba_create 전화를 걸 때 데이터가 손실되었습니다. 주석 @Template("")을 추가하지 않았습니다. 그게 해결책이야, 희망은 같은 문제를 실행하는 모든 사람들을 위해 작동한다.

0
/** 
* Displays a form to create a new Bank Account 
* 
* @Route("/account/new", name="wba_new") 
*/ 
public function newBankAccountAction() 
{ 
    $entity = new Account(); 
    $form = $this->createForm(new AccountType(), $entity); 

    return $this->render('BankBundle:BankAccount:new.html.twig',array(
      'entity' => $entity, 
      'form' => $form->createView(), 
    )); 
}