我找到了答案,比我类似的问题,但我不明白它是如何工作的,我应该在我的代码改变什么。所以,我请你帮忙,我有这样的错误信息:
选项“0”不存在。定义的选项是: “动作”, “allow_extra_fields”, “allow_file_upload”, “ATTR”, “auto_initialize”, “block_name”, “by_reference”, “化合物”, “约束”, “csrf_field_name”, “csrf_message”,“csrf_protection ”, “csrf_token_id”, “csrf_token_manager”, “数据”, “data_class”, “已禁用”, “empty_data”, “error_bubbling”, “error_mapping”, “extra_fields_message”, “帮助”, “help_attr”, “inherit_data” “invalid_message”, “invalid_message_parameters”, “标签”, “label_attr”, “label_format”, “映射”, “方法”, “post_max_size_message”, “property_path”, “需要”, “translation_domain”, “裁剪”,“upload_max_size_message ”, “validation_groups”。
这是我喜欢的类型:
<?php
namespace App\Form;
use App\Entity\Equipment;
use App\Entity\Property;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PropertyType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('propertyCategory', ChoiceType::class, [
'required' => true,
'choices' => [
'Appartement' => 'Appartement',
'Maison' => 'Maison',
'Garage' => 'Garage',
'Bureau' => 'Bureau',
'Château' => 'Château',
'Commerce' => 'Commerce',
]
])
->add('uniqueName', TextType::class, ['required' => true, 'label' => 'Nom unique'])
->add('address', TextType::class, ['required' => true, 'label' => 'Adresse'])
->add('city', TextType::class, ['required' => true, 'label' => 'Ville'])
->add('zipcode', IntegerType::class, ['required' => true, 'label' => 'Code postal'])
->add('country', CountryType::class, ['required' => true, 'label' => 'Pays'])
->add('surfaceInSquareMeter', IntegerType::class, [
'required' => true,
'label' => 'Surface en m²'
])
->add('numberOfPiece', IntegerType::class, ['required' => true, 'label' => 'Nombre de pièces'])
->add('description', TextType::class, ['required' => false, 'Description'])
->add('equipments', EntityType::class, [
'required' => false,
'label' => 'Equipements',
[
'class' => Equipment::class,
'multiple' => true,
'expanded' => true,
'choice_label' => 'name'
]
])
->add('locationCategory', ChoiceType::class, [
'required' => true,
'choices' => [
'Meublé' => 'Meublé',
'Non meublé' => 'Non meublé',
]
])
->add('rentExcludingCharges', NumberType::class, [
'required' => true,
'label' => 'Loyer hors charges'
])
->add('charges', NumberType::class, ['required' => true, 'label' => 'Charges'])
->add('purchasePrice', NumberType::class, ['required' => true, 'label' => 'Prix d\'achat']);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Property::class,
]);
}
}
希望你理解我的英语,有人可以帮我(和我解释如何避免再去做这个错误)
谢谢
编辑:有一个与那些没用的[]中存在的问题
->add('equipments', EntityType::class, [
'required' => false,
'label' => 'Equipements',
[
'class' => Equipment::class,
'multiple' => true,
'expanded' => true,
'choice_label' => 'name'
]
])
我解决了,但错误信息是相同的
在这里你丢失了一些标签attribut:
->add('description', TextType::class, ['required' => false, 'Description'])
我认为你有过少[]中:
->add('equipments', EntityType::class, [
'required' => false,
'label' => 'Equipements',
//[
'class' => Equipment::class,
'multiple' => true,
'expanded' => true,
'choice_label' => 'name'
//]
])