i have a problem i think when i try to upload a file ,here is the message :
The option "0" does not exist. Defined options are: "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".
here my UserType :
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
{ /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id;
/**
* @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;
}
before this error i had nothing , i was upload a picture :
somebody can helm me please?
controller edit :
/**
* @Route("/mon-espace/{id}/edit", name="edit")
* @param Request $request
* @param User $user
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function editAction(Request $request, User $user)
{
$editForm = $this->createForm(UserType::class, $user);
/* dump($user);die();*/
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid())
{
$file = $user->getAttachment();
$fileName = md5(uniqid()).'.'.$file->guessExtension();
$file->move($this->getParameter('attachment_directory'), $fileName);
$user->setAttachment($fileName);
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('monEspace',array('user'=> $user->getId()));
}
return $this->render('@User/profil/edit.html.twig' , array(
'user'=> $user,
'editForm' => $editForm->createView()
));
}