1

我如何从表单生成器中获取字段值?

我的控制器:

$region = new Region();
$region->setName('TEMP!!');

$formBuilder = $this->createFormBuilder(array('region' => $region));

$formBuilder->add('region', new RegionAjaxType);

和表格类型:

/**
 * @{inerhitDoc}
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $region = ....
    $builder
       ->add('name', 'text');
}

我想从构建器表单中获取区域对象以获取变量。

4

1 回答 1

0

选项有参数“数据”

示例用法:

/**
 * @{inerhitDoc}
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $region = $options['data'];
    $builder
       ->add('name', 'text');
}

并控制使用类型OptionsResolver

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver
        ->setDefaults(array(
            'region' => new Region
        ))
        ->addAllowedTypes(array(
            'region' => 'Acme\DemoBundle\Entity\Region',
        ))
    ;
}
于 2013-02-08T10:38:18.097 回答