Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过多种结果提高实体输入性能Symfony2_Php_Symfony_Doctrine Orm_Entity - Fatal编程技术网

Php 通过多种结果提高实体输入性能Symfony2

Php 通过多种结果提高实体输入性能Symfony2,php,symfony,doctrine-orm,entity,Php,Symfony,Doctrine Orm,Entity,我有一个带有实体输入字段的表单,它加载了一个可部署的(选择选项),其中有120000个结果。渲染这会使页面最多需要30秒才能加载 您知道在symfony中处理这种类型的控件表单的其他方法吗 表格: public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name', 'text') ->add('contact', 'text', ar

我有一个带有实体输入字段的表单,它加载了一个可部署的(选择选项),其中有120000个结果。渲染这会使页面最多需要30秒才能加载

您知道在symfony中处理这种类型的控件表单的其他方法吗

表格:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
    ->add('name', 'text')
    ->add('contact', 'text', array(
            'required' => false
    ))
    ->add('address', 'text')
    ->add('id_spanish_town', 'entity', array(
            'class' => 'PanelBundle:SpanishTowns',
            'query_builder' => function(EntityRepository $er){
                return $er->createQueryBuilder('z')
                ->orderBy('z.name', 'asc');
            }
    ))
    ->add('password', 'repeated', array(
            'type' => 'password',
            'first_name' => 'pass',
            'second_name' => 'pass_confirm',
            'mapped' => false,
            'required' => false
    ))
    ->add('email', 'email', array(
            'required' => false
    ))
    ->add('about_us', 'textarea', array(
            'required' => false
    ))
    ->add('save', 'submit', array(
            'label' => 'Save'
    ));
}

问候并感谢您。

我不提供所有产品的选择,而是使用一些项目建议和ajax/json提供程序,最多15个项目

我们有大约60000种产品,这将使如此庞大的选择导致数据库崩溃

简化版的
QueryBuilder

// ...

/**
 * @var int
 */
const ITEMS_LIMIT = 15;


public function getDataForResponse($entityName, $name)
{
    $queryBuilder = $this->entityManager->createQueryBuilder()
        ->select('e.id, e.name')
        ->from($entityName, 'e');
        ->where('e.name LIKE :name')
        ->setParameter('name', '%' . $name . '%');

    return $queryBuilder->getQuery()
        ->setMaxResults(self::ITEMS_LIMIT)
        ->getResult(Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
}

您可以尝试缓存,也可以在不水合的情况下获取实体,只需直接查询所需字段(ID和select的描述),全世界没有人在等待从120.000个选项中做出选择。相反,您可以使用jquery的自动完成功能