我有一个实体“合约”和另一个实体“货币” 如何将实体货币的ID传递给我的实体合同?
对于每个都有一个货币ID,这个ID必须由FormBuilder在我的实体Contract中插入表合约中的“currency_id”字段。 有关实体关系“合同”和实体“货币” 无法挽救合同FormBuilder的货币ID? 我搜索了文档,但一无所获!
以下是我的表单构建器的代码:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('currency_id', 'choice', array('label' => 'Moeda:', 'choices' => array(''=>'', 1 => 'BRL', 2 => 'USD', 3 => 'EUR'), 'required' => true))
->add('safeExpenses', 'checkbox', array('label' => 'Seguro de Despesas:'))
->add('valueSafeExpenses', 'text', array('label' => 'Valor:'))
->add('safeTax', 'checkbox', array('label' => 'Seguro de Impostos:'))
;
}
我会插入CURRENCY_ID - > 1 - BRL,在我的表合同中,在字段(列)“currency_id”
我的控制器:
public function createAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$customer = $em->getRepository('FidcargoPortalBundle:Customer')->findAll();
$currency = $em->getRepository('FidcargoPortalBundle:Currency')->findAll();
$entity = new Contract();
$entity ->setDtContract = (new \DateTime());
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$entity ->setRegistrationStatus(Contract::AGUARDANDO_APROVACAO);
$customer = $em->getRepository('FidcargoPortalBundle:Customer')->find($request->get('customer_id'));
$customer = $em->getRepository('FidcargoPortalBundle:Currency')->find($request->get('currency_id'));
$entity ->setCustomer($customer);
$entity ->setCurrency($cusrrency);
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('contract_approve', array(
'customer' => $customer,
'id' => $entity->getId())));
}