我找到了一个与我类似的问题的答案,但是我不明白它的工作原理以及我应该在代码中进行哪些更改。所以,我请求您帮助,我收到此错误消息:
选项“ 0”不存在。定义的选项为:“操作”,“ allow_extra_fields”,“ allow_file_upload”,“ attr”,“ auto_initialize”,“ block_name”,“ by_reference”,“ compound”,“ constraints”,“ 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”,“ help_attr”,“ heritit_data”, “ invalid_message”,“ invalid_message_parameters”,“ label”,“ label_attr”,“ label_format”,“ mapped”,“ method”,“ post_max_size_message”,“ property_path”,“ required”,“ translation_domain”,“ trim”,“ 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,
]);
}
}
希望您能理解我的英语,并且有人可以帮助我(并向我解释如何避免再次犯此错误)
Thx
编辑:
中的那些useless []有问题->add('equipments', EntityType::class, [
'required' => false,
'label' => 'Equipements',
[
'class' => Equipment::class,
'multiple' => true,
'expanded' => true,
'choice_label' => 'name'
]
])
,我已解决但错误消息相同
答案 0 :(得分:0)
我认为您的[]太少了:
->add('equipments', EntityType::class, [
'required' => false,
'label' => 'Equipements',
//[
'class' => Equipment::class,
'multiple' => true,
'expanded' => true,
'choice_label' => 'name'
//]
])
答案 1 :(得分:0)
这里您缺少标签属性:
->add('description', TextType::class, ['required' => false, 'Description'])