Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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/9/git/21.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 Symfony 3 FormType-通过选项数组的实体_Php_Arrays_Forms_Symfony_Entity - Fatal编程技术网

Php Symfony 3 FormType-通过选项数组的实体

Php Symfony 3 FormType-通过选项数组的实体,php,arrays,forms,symfony,entity,Php,Arrays,Forms,Symfony,Entity,我想知道如何正确地传递实体和createForm函数中的另一个变量 让我解释一下,我想这样做: $repo = $em->getRepository('ProjectBundle:Organisation\Organisation'); $list = $repo->children($this->getUser()->getOrganisation()); $form = $this->createForm('Pro

我想知道如何正确地传递实体和createForm函数中的另一个变量

让我解释一下,我想这样做:

$repo = $em->getRepository('ProjectBundle:Organisation\Organisation');
            $list = $repo->children($this->getUser()->getOrganisation());
            $form = $this->createForm('ProjectBundle\Form\Robot\RobotType', array($entity,$list));
我需要向FormType传递另一个变量,因此我直接使用数组

我的表单类型:

<?php

namespace ProjectBundle\Form\Robot;

use ProjectBundle\Entity\Robot\Robot;
use ProjectBundle\Form\User\UserType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class RobotType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('serial_number')
            ->add('shell_color',ChoiceType::class,array(
                'choices' => Robot::getArrayShellColor()
            ))
            ->add('tray1Color',ChoiceType::class,array(
                'choices' => Robot::getTrayColor()
            ))
            ->add('tray2Color',ChoiceType::class,array(
                'choices' => Robot::getTrayColor()
            ))
            ->add('tray3Color',ChoiceType::class,array(
                'choices' => Robot::getTrayColor()
            ))
            ->add('hasBattery')
            ->add('volume')
            ->add('organisation',null,array('choices' => $options['data'][1]));
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'ProjectBundle\Entity\Robot\Robot'
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'projectbundle_robot_new';
    }


}
这是正常的,因为现在我在数组中传递它,现在是我的变量
$options['data'][0]
包含了我的对象

怎么办?
谢谢

您应该将ProjectBundle\Entity\Robot\Robot Entity作为第二个参数传递给createForm方法,并将options数组作为第三个参数传递给createForm方法

$form = $this->createForm('ProjectBundle\Form\Robot\RobotType', $entity, array($list));

检查EntityType和参数query\u builder
$form = $this->createForm('ProjectBundle\Form\Robot\RobotType', $entity, array($list));