我有一个问题,我想当我尝试上传文件时,这里是消息:
选项“0”不存在。定义的选项包括:“action”,“allow_extra_fields”,“attr”,“auto_initialize”,“block_name”,“by_reference”,“compound”,“constraints”,“csrf_field_name”,“csrf_message”,“csrf_protection”,“csrf_token_id “,”csrf_token_manager“,”data“,”data_class“,”disabled“,”empty_data“,”error_bubbling“,”error_mapping“,”extra_fields_message“,”inherit_data“,”invalid_message“,”invalid_message_parameters“,”label“, “label_attr”,“label_format”,“mapped”,“method”,“multiple”,“post_max_size_message”,“property_path”,“required”,“translation_domain”,“trim”,“upload_max_size_message”,“validation_groups”。
这是我的UserType:
bookname user total
a u1 2
b u1 1
a u2 1
b u2 0
{ / ** * @ORM \ Id * @ORM \ Column(type =“integer”) * @ORM \ GeneratedValue(strategy =“AUTO”) * / protected $ id;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('lastName',TextType::class, array(
'label'=> 'Nom',
'attr'=> ['placeholder'=>'Votre Non']
))
->add('firstName',TextType::class, array(
'label'=> 'Prénom',
'attr'=> ['placeholder'=>'Votre Prénom']
))
->add('username',TextType::class, array(
'label'=> 'Nom d\'utilisateur',
'attr'=> ['placeholder'=>'Non d\'utilisateur ']
))
->add('email',EmailType::class, array(
'label'=> 'Email',
'attr'=> ['placeholder'=>'Votre Email']
))
->add('adresse',TextType::class, array(
'label'=> 'Votre Adresse',
'attr'=> ['placeholder'=>'Votre Adresse']
))
->add('ville',TextType::class, array(
'label'=> 'Ville',
'attr'=> ['placeholder'=>'Votre Ville']
))
->add('pays',TextType::class, array(
'label'=> 'Pays',
'attr'=> ['placeholder'=>'Votre Pays']
))
->add('codePostal',TextType::class, array(
'label'=> 'Code Postal',
'attr'=> ['placeholder'=>'Code Postal']
))
->add('telephone',TextType::class, array(
'label'=> 'Télephone',
'attr'=> ['placeholder'=>'Votre telephone']
))
->add('dateAnniversaire', BirthdayType::class, array(
'label'=> 'Date D\'anniversaire',
'placeholder' => array(
'day'=>'Jour','month'=>'Mois' ,'year'=>'Année'
)
))
->add('attachment',FileType::class,array(
'label' => 'Photo de profil',
'required' => false, (array(
'data_class' => null
))
))
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'UserBundle\Entity\User'
));
}
class User extends BaseUser
在此错误之前我什么都没有,我上传了一张图片:
有人可以请你帮忙吗?控制器编辑:
/**
* @var string
* @ORM\Column(name="last_name" , type="string" , length=25, nullable=true)
*/
protected $lastName;
/**
* @var string
* @ORM\Column(name="first_name", type="string", length=25, nullable=true)
*/
protected $firstName;
/**
* @var string
*
* @ORM\Column(name="date_anniversaire", type="datetime", nullable = true)
*/
protected $dateAnniversaire;
/**
* @var string
*
* @ORM\Column(name="adresse", type="string", length=255, nullable=true)
*/
protected $adresse;
/**
* @var string
* @ORM\Column(name="ville", type="string", length=25, nullable=true)
*/
protected $ville;
/**
* @var string
* @ORM\Column(name="pays", type="string", length=50, nullable=true)
*/
protected $pays;
/**
* @var string
* @ORM\Column(name="code_postal", type="string",length=5, nullable=true)
*/
protected $codePostal;
/**
* @var string
* @ORM\Column(name="telephone", type="string", length=15, nullable=true)
*/
protected $telephone;
/**
* @ORM\ManyToMany(targetEntity="UserBundle\Entity\User", cascade={"persist"})
*/
protected $users;
/**
* @var string
* @ORM\Column(type="string")
* @Assert\File(
* mimeTypes={"image/jpeg","image/gif","image/png"},
* mimeTypesMessage = "Svp inserer une image valide (png,jpg,jpeg)")
*/
protected $attachment;
public function __construct()
{
parent::__construct();
}
/**
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param string $lastName
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param string $firstName
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
/**
* @return string
*/
public function getDateAnniversaire()
{
return $this->dateAnniversaire;
}
/**
* @param string $dateAnniversaire
*/
public function setDateAnniversaire($dateAnniversaire)
{
$this->dateAnniversaire = $dateAnniversaire;
}
/**
* @return string
*/
public function getAdresse()
{
return $this->adresse;
}
/**
* @param string $adresse
*/
public function setAdresse($adresse)
{
$this->adresse = $adresse;
}
/**
* @return string
*/
public function getVille()
{
return $this->ville;
}
/**
* @param string $ville
*/
public function setVille($ville)
{
$this->ville = $ville;
}
/**
* @return string
*/
public function getPays()
{
return $this->pays;
}
/**
* @param string $pays
*/
public function setPays($pays)
{
$this->pays = $pays;
}
/**
* @return string
*/
public function getCodePostal()
{
return $this->codePostal;
}
/**
* @param string $codePostal
*/
public function setCodePostal($codePostal)
{
$this->codePostal = $codePostal;
}
/**
* @return string
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* @param string $telephone
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
}
/**
* @return mixed
*/
public function getUsers()
{
return $this->users;
}
/**
* @param mixed $users
*/
public function setUsers($users)
{
$this->users = $users;
}
/**
* Add user
*/
public function addUser($user)
{
$this->users[] = $user;
}
/**
* Remove user
*/
public function removeUser($user)
{
$this->users->removeElement($user);
}
/**
* @return mixed
*/
public function getAttachment()
{
return $this->attachment;
}
/**
* @param string $attachment
*/
public function setAttachment($attachment)
{
$this->attachment = $attachment;
}
答案 0 :(得分:0)
您在最后 - >添加
后忘记了 - > getForm() .
.
. ->add('attachment',FileType::class,array(
'label' => 'Photo de profil',
'required' => false, (array(
'data_class' => null
))
))
->getForm();
<强>更新强>
你没有实体上的字段用户名...所以如果你想使用多对多关系提示,你必须做这样的事情。
->add('users',EntityType::class, array(
'class' => 'AppBundle:User',
'label'=> 'Nom d\'utilisateur',
'attr'=> ['placeholder'=>'Non d\'utilisateur ']
))