在尝试填充$ form对象时,Symfony Form超时

时间:2016-04-24 20:05:43

标签: symfony doctrine-orm doctrine symfony-forms

当我只有数据库中每个实体的一些记录时,下面的Symfony表单在开发中工作正常。但是,一旦我将其连接到生产数据库的摘录,页面就会超时。

此提取中的数据库表的大小更大(每个大约800条记录),但没有任何理由可以证明它完全超时。我假设这个问题误解了如何最好地填充$batch

控制器:

public function batchInvoicesAction(Request $request)
{
    $em = $this->getDoctrine()->getManager();
    $members = $em->getRepository('AppBundle:Member')->findActiveMembers();
    $batch = new InvoiceBatch();

    foreach ($members as $member) {
        $invoice = new Invoice();
        $invoice->setMemberId($member);
        $invoice->setSelected(True);
        $invoice->setCreatedate(new \Datetime());
        $invoice->setAmount($member->getDefaultinvoiceamount());
        $invoice->setCurrency($member->getDefaultinvoicecurrency());
        $invoice->setinvoicebatchid($batch);
        $batch->addInvoiceId($invoice);
        # exit(VarDumper::dump($batch));
    }

    $form = $this->createForm(InvoiceBatchType::class, $batch);
    $form->handleRequest($request);
    if ($form->isSubmitted() && ($form->isValid())) {

        $batchform = $form->getData();

        foreach ($batchform->getInvoiceids() as $invoiceform) {
            if ($invoiceform->getSelected() == False) {
                $batchform->removeInvoiceId($invoiceform);
            } else {
                $em->persist($invoiceform);
            }
        }
        $em->persist($batchform);
        $em->flush();
        return $this->redirectToRoute('view_monthly_invoices');
    }

    return $this->render('invoices/new.batch.invoice.html.twig', array(
        'page_title' => 'Invoices',
        'message' => 'Batch loading of invoices',
        'form' => $form->createView(),
    ));
}

存储库功能代码为:

public function findActiveMembers()
{
    return $this->getEntityManager()
        ->createQuery
        (
            'SELECT m
             FROM AppBundle:Members m
             WHERE m.active= :active
             ORDER BY m.familyname1, m.familyname2, m.firstname'
        )
        ->setParameter('active' ,true)
        ->getResult();
}

如果有任何帮助:

1。部分$batch的Vardump:

{#1022 ▼
  #id: null
  #invoice_ids: ArrayCollection {#1023 ▼
    -elements: array:1 [▼
      0 => Invoice {#1024 ▼
        #id: null
        #invoicebatch_id: InvoiceBatch {#1022}
        #member_id: Member {#1049 ▶}
        #payment_ids: ArrayCollection {#1027 ▶}
        #attendc_ids: ArrayCollection {#1025 ▶}
        #attende_ids: ArrayCollection {#1044 ▶}
        #bankreceipt: null
        #aggregate_payment: 0
        #selected: true
        #amount: "0.00"
        #currency: "S"
        #invoicedate: null
        #createdate: DateTime {#19571 ▶}
        #modifydate: null
        #billedmonth: null
        #description: null
      }
    ]
  }

2。我的自定义formTypes - 这可能是问题,因为我仍然试图了解FormTypes。该页面只有一个InvoiceBatchType,其数组Invoice_ids用作CollectionType,InvoiceForBulkType

class InvoiceBatchType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('batchevent', TextType::class, array(
            ))
            ->add('invoice_ids', CollectionType::class, array(
                'entry_type' => InvoiceForBulkType::class,
            ))
        ;
    }

    /* ... */
}

class InvoiceForBulkType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('selected', CheckboxType::class, array(
                'label'    => ' ',
                'required' => false,
            ))
            ->add('member_id', EntityType::class, array(
                    'class' => 'AppBundle:Member',
                    'choice_label' => 'FullName',
                    'label'=>'Member',
                    'disabled'=>true,
                )
            )
            ->add('amount', TextType::class, array(
                'label' => 'Amount',
            ))
            ->add('currency',ChoiceType::class, array(
                'choices' => array('Soles' => 'S', 'Dollars' => 'D'),
                'choices_as_values' => true,
            ))
            ->add('invoicedate', DateType::class, array(
                'widget' => 'single_text',
                'data' => new \DateTime('now'),
                'format' => 'dd/MMM/yyyy',
                'label' => 'Date of invoice',
                'attr'=> array(
                    'class'=>'datepicker',
                )
            ))
            ->add('description', TextType::class, array(
                'required'=>false,
            ))
        ;
    }

    /*...*/
}

0 个答案:

没有答案