2013-04-01 2 views
1

Symfony2를 사용하여 db에서 레코드를 제거하는 데 문제가 있습니다. 누군가를 원하면 나를 도울 수 있습니다.Symfony2 레코드 삭제

EntityManager#remove() expects parameter 1 to be an entity object, array given. 

내 URL은 다음과 같이 :

{{ path('purchase_order_remove_line_item', { 'id': purchaseOrderLineItem.id }) }} 

내 "ID를합니까이이 실행될 때, 나는이 오류가

// Get user's account 
$account = $this->getUser()->getAccount(); 

// Get manager 
$em = $this->getDoctrine()->getManager(); 

// Get entity 
$entity = $em->getRepository('WICPurchaseOrderLineItemBundle:PurchaseOrderLineItem')->findBy(array('account'=>$account->getId(), 'id'=>$id)); 

// If not entity 
if (!$entity) { 
throw $this->createNotFoundException('Unable to find this entity.'); 
} 

// Remove the record... 
$em->remove($entity); 
$em->flush(); 

// Go to this url... 
return $this->redirect($this->generateUrl('purchaseOrder_view', array('id' => '8'))); 

: 여기

내 코드입니다 "번호가 먼저 객체로 바뀌어야합니까? 이 문제를 해결하는 방법을 모르겠지만 여전히 Symfony를 배우십시오.

누구든지 의견이 있으십니까?

답변

3

findBy 메서드 대신 findOneBy 메서드를 사용해야합니다.

$entity = $em->getRepository('WICPurchaseOrderLineItemBundle:PurchaseOrderLineItem')->findOneBy(array('account'=>$account->getId(), 'id'=>$id));