我有需要处理 500 多个实体实例的表单集合。在我将超时时间增加到 60 秒并增加 max_input_vars 表单工作后,但令人讨厌的是它有多慢。渲染表单很慢,但提交那个大表单很麻烦。
我正在考虑创建纯 HTML 表单,但还有其他一些缺点作为验证。那么,是否有任何适当的方法可以通过 symfony 形式处理大量数据?
控制器:
public function ratesCardAction() {
$bannerList = $this->data;
$em = $this->getDoctrine()->getManager();
$form = $this->createForm(new AdvertiserRatesType($bannerList));
if ('POST' == $this->getRequest()->getMethod()) {
$form->handleRequest($this->getRequest());
$advertiserCampaign = $form->getData();
if ($form->isValid()) {
foreach ($advertiserCampaign['campaignsAdZones'] as $campaignAdZone) {
$em->persist($campaignAdZone);
}
$em->flush();
}
}
return array(
'form' => $form->createView()
);
}
class AdvertiserRatesType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder ->add('campaignsAdZones', 'collection', array(
'type' => new AdvertiserRatePerCountryType(),
'data' => $this->rates,
'empty_data' => null,
'options' => array(
'attr' => array('class' => 'campaignAdZoneItem')
)
))
;
}
}
...
和嵌入的形式看起来像:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('class', 'entity', array(
'class' => 'AcmeCmsBundle:PublisherTypes',
'property' => 'class',
'read_only' => true,
'disabled' => true
)
)
->add('country', 'entity', array(
'class' => 'AcmeCmsBundle:Countries',
'property' => 'name',
)
)
->add('text1')
->add('text2')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\CmsBundle\Entity\Rates'
));
}