Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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 - Fatal编程技术网

Php 将集合用作类型为Symfony2表单的实体

Php 将集合用作类型为Symfony2表单的实体,php,symfony,Php,Symfony,是否可以生成选择列表,从数据库中检索选项,并有选项(使用JS)来乘法字段 我复制了我的代码,也许会有帮助 $builder->add('device', 'collection', array( 'type' => 'entity', 'label' => ' ', 'options' => array( 'class' => 'TrashTrashAdminBundle:DeviceType', 'pro

是否可以生成选择列表,从数据库中检索选项,并有选项(使用JS)来乘法字段

我复制了我的代码,也许会有帮助

$builder->add('device', 'collection', array(
    'type' => 'entity',
    'label' => ' ',
    'options' => array(
         'class' => 'TrashTrashAdminBundle:DeviceType',
         'property' => 'name',
         'query_builder' => function(EntityRepository $er) {
             return $er->createQueryBuilder('d')
                 ->where('d.isLighting = 1');
          },
     ),
     'attr' => array('class' => 'form-control device')
))

您正试图以处理
实体
字段类型的方式处理
集合
字段类型。您应该更改
实体的
集合

$builder->add('device', 'entity', array(                
    'options' => array(
        'class' => 'TrashTrashAdminBundle:DeviceType',
        'property' => 'name',
        'query_builder' => function(EntityRepository $er) {
                return $er->createQueryBuilder('d')
                    ->where('d.isLighting = 1');
            },
    ),
    'attr' => array(
        'class' => 'form-control device'
    ))
);
生成选择框后,您可以根据自己的意愿进行更改,如您所述