0
我有三個實體:發票,支付和結果呼叫的實體的方法在控制器
實體之間的關係是: 結果(1,1)------------- (1,n)發票(1,n)---------------(1,1)Payment 這是我的問題:我想在我的PaymentController中創建一個新的payement,我檢索發票實體,並在同一個PaymentController中創建一個新的結果。
這裏是我的PaymentController代碼:
use MyApp\AccountBundle\Entity\Result;
class PaymentController extends Controller
public function createAction()
{
$entity = new Payment();
$request = $this->getRequest();
$form = $this->createForm(new PaymentType(), $entity);
$form->bindRequest($request);
$amount=$form->get('amountreceived')->getData();
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$invoice = em->getRepository('MyAppAccountBundle:Invoice')->find($entity->getInvoice()->getId())
if (!$invoice) {
throw $this->createNotFoundException('Unable to find Invoice entity.');
}
$result=new Result();
$result=setDebitAmount($amount);
$result=setCreditAmount(0);
$result=setInvoice($invoice);
$em->persist($result);
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('payment_show', array('id' => $entity->getId())));
}
return $this->render('MyAppAccountBundle:Payment:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView()
));
當執行PaymentController(鑑於)我得到錯誤: 致命錯誤:調用未定義的函數MyApp的\ AccountBundle \控制器\ setDebitAmount()在C:\ WAMP \ WWW \帳戶的\ src \ MyApp的\ AccountBundle \控制器\ PaymentController.php上線...
預先感謝
非常感謝你@ forgottenbas,它的工作原理, – Avi