我想在 Symfony 中向表單添加一個額外的欄位,但如果它沒有系結到物體屬性,它將不會接受它。
如果有人知道我可以做些什么來修復它,非常感謝提前!
這是表單型別,我正在嘗試添加“額外”欄位:
<?php
namespace App\Form;
use App\Entity\Dossier;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class InscriptionBCType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('extra', TextType::class, [
'label' => 'Les besoins qui motivent votre demande (soyez exhaustif)',
'required' => false,
])
->add('Nom')
->add('Prenom')
->add('Mail')
->add('civilite', ChoiceType::class, [
'choices' => [
'Monsieur' => "Monsieur",
'Madame' => "Madame",
],
]) ->add('telephone')
->add('adresse')
->add('code_postal')
->add('ville')
->add('projet', TextType::class, [
'label' => 'votre projet entrepreneurial (SI VOUS EN AVEZ UN)(FACULTATIF)',
'required' => false,
])
->add('besoin', TextType::class, [
'label' => 'Les besoins qui motivent votre demande (soyez exhaustif)',
'required' => false,
])
->add('budgetCPF', TextType::class, [
'label' => 'Votre budget CPF mobilisable',
'required' => false,
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Dossier::class,
]);
}
}
我得到這個錯誤:
Can't get a way to read the property "extra" in class "App\Entity\Dossier".
uj5u.com熱心網友回復:
我知道我已經在評論中回答了這個問題,但并不是每個人都讀過,這就是為什么我將其發布為答案,如果你想忽略一個欄位,你必須使用映射,例如:
add("extra"=> 'file', array("mapped"=>false))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/523591.html
