Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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_Entity Framework_Symfony_Entity_Dynamicform - Fatal编程技术网

Php Symfony2形成动态种群

Php Symfony2形成动态种群,php,entity-framework,symfony,entity,dynamicform,Php,Entity Framework,Symfony,Entity,Dynamicform,我有一个描述学校的实体,它与另一个描述“阶段”的实体相关,该“阶段”由一个学校->多个阶段组成 学校有以下领域(我只列出相关领域/方法): 而舞台实体是这样的: namespace A4U\FormBundle\Entity; class Stage { . . . /** * @ORM\ManyToOne(targetEntity="A4U\DataBundle\Entity\StuAnagScuole", inversedBy="stages")

我有一个描述学校的实体,它与另一个描述“阶段”的实体相关,该“阶段”由一个学校->多个阶段组成

学校有以下领域(我只列出相关领域/方法):

而舞台实体是这样的:

namespace A4U\FormBundle\Entity;
class Stage
{
    .
    .
    .
    /**
     * @ORM\ManyToOne(targetEntity="A4U\DataBundle\Entity\StuAnagScuole", inversedBy="stages")
     * @ORM\JoinColumn(name="attendedSchool_id", referencedColumnName="idRecord")
     */
    protected $attendedSchool;
    .
    .
    .
}
我创建了一个表单,允许用户注册一个阶段。在某些时候,用户必须从数据库中保存的学校列表中输入他所就读的学校

由于有7000多所学校,我必须对它们进行筛选:

1) 首先,用户选择一个区域

2) 然后他选择了一个地区

3) 然后是一座城市

4) 最后是学校

所以我想为每个“过滤器”添加一个实体字段(第一个是这样的):

在实体存储库中:

/**
 * Get Regioni
 *
 * @return array 
 */
public function getRegioni()
{
    $qb = $this->getEntityManager()->createQueryBuilder();

    $qb->select('s0')
    ->from('A4UDataBundle:StuAnagScuole', 's0')
    ->groupBy('s0.regione');

    return $qb;
}
因此,此时我想在“attendedSchoolRegion”字段中添加一个POST_SUBMIT事件,以动态填充“attendedSchoolDistrict”,如下所示:

->add('attendedSchoolRegion', 'entity', array(
    /*
        usando mapped false si dice a simfony che il campo non deve essere scritto
        nell'entità
    */
    'mapped' => false,
    'label' => 'Regione della scuola*',
    'class' => 'A4UDataBundle:StuAnagScuole',
    'query_builder' => function(EntityRepository $er) {
        return $er->getRegioni();
        },
    'property' => 'regione',
    'attr' => array(
        'class' => 'form-control',
        'placeholder' => 'Campo di studi'
        )
    ))
    $addDistrict = function (FormInterface $form, StuAnagScuole $attendedSchoolRegion)
    {
        //$districts = $attendedSchoolRegion->getProvincie($attendedSchoolRegion);

            $form->add('attendedSchoolDistrict', 'entity', array(
            'mapped' => false,
            'label' => 'Provincia della scuola di provenienza*',
            'class' => 'A4UDataBundle:StuAnagScuole',
            'query_builder' => function(EntityRepository $er) {
                return $er->getProvincie($attendedSchoolRegion);
                },
            'property' => 'provincia',
            'attr' => array(
                'class' => 'form-control',
                )
            ));

    };

    $builder->get('attendedSchoolRegion')->addEventListener(
        FormEvents::POST_SUBMIT,
        function (FormEvent $event) use ($addDistrict){
            $attendedSchoolRegion = $event->getForm()->getData();
            $addDistrict($event->getForm()->getParent(), $attendedSchoolRegion);
        }
    );
等等,直到学校被选中。在这个过程结束时,我只希望所选学校的id被保存到现场就读学校下的DB中

但我似乎无法将所选区域的值传递给“getProvincie”方法

以下是错误:

Catchable Fatal Error: Argument 2 passed to A4U\FormBundle\Form\Type\StageType::A4U\FormBundle\Form\Type\{closure}() must be an instance of A4U\DataBundle\Entity\StuAnagScuole, none given...
我希望我说得够清楚了,谢谢你的帮助

Catchable Fatal Error: Argument 2 passed to A4U\FormBundle\Form\Type\StageType::A4U\FormBundle\Form\Type\{closure}() must be an instance of A4U\DataBundle\Entity\StuAnagScuole, none given...