How to add additional non-entity fields to entity form in Symfony2

前端 未结 2 819
醉酒成梦
醉酒成梦 2020-12-30 19:29

I have created form with one element from Entity:

$promo = new Promo();

$form = $this->createFormBuilder($promo)
        ->add(\'code\', \'text\')
            


        
相关标签:
2条回答
  • 2020-12-30 20:01

    Use the property_path option:

    $builder->add('image', 'file', [
        'property_path' => false,
    ]);
    
    0 讨论(0)
  • 2020-12-30 20:14

    Use mapped:

    $form = $this->createFormBuilder($promo)
        ->add('code', 'text')
        ->add('image', 'file', array(
                    "mapped" => false,
                ))
        ->getForm();
    

    In old Symfony versions (2.0 and earlier), use property_path:

    $form = $this->createFormBuilder($promo)
        ->add('code', 'text')
        ->add('image', 'file', array(
                    "property_path" => false,
                ))
        ->getForm();
    

    "property_path" was removed in Symfony 2.3

    0 讨论(0)
提交回复
热议问题