使用handleRequest验证表单的Symfony 2.3非常慢 [英] Symfony 2.3 validating form with handleRequest is insanely slow

查看:140
本文介绍了使用handleRequest验证表单的Symfony 2.3非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在提交一个带有很多字段的表单,并试图用Symfony文档中显示的 handleRequest($ request)来验证它。
我的实体非常大,与其他实体有很多关系。
handleRequest($ request)正在验证每个提交的表单字段并检查错误。

发现在提交我的主要实体的相关实体(例如办公室的人)的ID时, handleRequest 将在内部获得相关实体的所有对象(全部

我认为它应该检查提交的id是否存在于另一个表中,获取相关的实体对象并检查它是否有错误(而不是获取所有相关表)。

如果您检查并调试Symfony2 handleRequest 的源代码, code>,你可能很容易发现同样的问题:

Form / Form.php

  //将数据规范化为统一表示
$ normData = $ this-> viewToNorm($ viewData);
$ value = $变形金刚[$ i] - > reverseTransform($ value);

如何在不处理此问题的情况下验证表单,这使得验证表单的速度非常慢用 handleRequest($ request)



如果我不使用handleRequest来验证它,错误到我的形式为每个字段,我怎么可以手动验证每个字段,然后将错误添加到我的表单为每个字段,并显示他们在下一个视图?

解决方案

这个问题有点含糊,答案很大程度上取决于你的具体形式。请发布给您最困难时间的表单定义。



检查并确保您不是在这里获取关联的。 p>

handleRequest()将接受请求对象并构建表单描述的模型,至。



如果需要这些对象才能将初始表单上的数据显示给用户,或者验证提交时的数据,那么 entity >字段类型将获取您在其定义中告诉它的所有对象。例如,如果您显示的是大型选择列表,则需要所有这些数据。



过去有类似的问题,这是因为我正在使用许多选择字段被用作一系列多选复选框。我的瓶颈实际上是在树枝层,同时呈现了我作为单独实体存储的数千个复选框。



我从一组复选框切换到单个多选盒子,它显着提高了我的速度。

I am submitting a form with a lot of fields and trying to validate it with handleRequest($request) as it is shown in the Symfony documentation. My entity is very big and has a lot of relations with other entities. handleRequest($request) is validating each form field submitted and checking for errors.

The problem found is while submitting an id of a related entity of my main entity (in example a person of an office), handleRequest will internally get all objects of the related entity (the full table of the related entity, all persons) and hydrating them as objects.

I think it should just check if the submitted id exists in the other table, get that related entity object and check it for errors (instead of getting all the related table).

If you check and debug the source code of Symfony2 handleRequest, you may easily spot the same problem at this lines:

Form/Form.php

// Normalize data to unified representation
$normData = $this->viewToNorm($viewData);
$value = $transformers[$i]->reverseTransform($value);

How can I still validate the form without dealing with this issue which makes it insanely slow to validate a form with handleRequest($request)?

If I don't use handleRequest to validate it, which automatically add the errors to my form for each field, how could I manually validate each field and later add the errors to my form for each field and show them in the next view?

解决方案

This question is a little vague, and the answer very much depends on your specific form. Please post the form definition that is giving you the hardest time.

Check to make sure that you are not EAGER fetching associations here.

handleRequest() is going to take the request object and construct the model that your form describes, as your form defined it to.

If the objects are required in order to display data on your initial form to the user, or to validate the data on submit, the "entity" field type will fetch all of the objects you told it to in its definition. If you are displaying a big select list, for example, all of this data is needed.

I had a similar problem in the past and it was because I was using a lot of choice fields that were being used as a series of multiple select checkboxes. My bottleneck was actually in the twig layer while rendering out the thousands of checkboxes I had stored as separate entities.

I switched from a set of checkboxes to a single multi-select box and it increased my speed significantly.

这篇关于使用handleRequest验证表单的Symfony 2.3非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆