Symfony Form将变量选项从Collection传递给FormType

时间:2016-04-29 09:34:36

标签: php forms symfony-forms symfony

我有一个集合类型:

->add('tipi', CollectionType::class, array(
                'entry_type' => TipiType::class,
                'allow_add' => true,
                'prototype' => true,
                'mapped' => false,
                'entry_options' => array(
                    'required' => true,
                    'label' => false,
                )
            ))

扩展此formtype:

->add('tipi', EntityType::class, array(
      'label' => 'Tipo',
      'class' => 'AppBundle:Tipi',
      'attr' => array('class' => 'form-control'),
      'query_builder' => function (EntityRepository $er) {
          return $er->createQueryBuilder('t')
                    ->innerJoin('t.requests', 'r')
          ;
      },
  ));

在第一种形式类型中,我有一个以这种方式从控制器发出的选项:

$idRequest = $request->get('id');
$form = $this->createForm(RequestsType::class, $requests, array(
    'id_request' => $idRequest
));

在第一个我可以使用它,但在子FormType不。我会在集合类型中传递此变量。我怎么能这样做?

$form = $this->createForm(new YourForm($options), $class);

0 个答案:

没有答案