j'utilise le fosuserbundle et dans le formulaire d'inscription que j'ai hérité, j'ai rajouté des champs de type String (nom et prénom) et un champ (photo) qui est un clé étrangère:
voilà le code de chaque fichier
Utilisateurs\UtilisateursBundle\Entity\Photo.php
Utilisateurs\UtilisateursBundle\Entity\Utilisateurs.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 <?php namespace Utilisateurs\UtilisateursBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\validator\Constraints as Assert; /** * Photo * * @ORM\Table("photo") * @ORM\Entity(repositoryClass="Utilisateurs\UtilisateursBundle\Repository\PhotoRepository") * @ORM\HasLifecycleCallbacks */ class Photo { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="path", type="string", length=255) */ private $path; /** * @var string * * @ORM\Column(name="alt", type="string", length=125) */ private $alt; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set path * * @param string $path * @return Photo */ public function setPath($path) { $this->path = $path; return $this; } /** * Get path * * @return string */ public function getPath() { return $this->path; } /** * Set alt * * @param string $alt * @return Photo */ public function setAlt($alt) { $this->alt = $alt; return $this; } /** * Get alt * * @return string */ public function getAlt() { return $this->alt; } }
Utilisateurs\UtilisateursBundle\Form\Type\RegistrationFormType.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 <?php namespace Utilisateurs\UtilisateursBundle\Entity; use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity * @ORM\Table(name="utilisateurs") */ class Utilisateurs extends BaseUser { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\OneToOne(targetEntity="Utilisateurs\UtilisateursBundle\Entity\Photo", cascade={"persist","remove"}) * @ORM\JoinColumn(nullable=false) */ private $photo; /** * @ORM\Column(type="string", length=255) */ protected $name; /** * @ORM\Column(type="string", length=255) */ protected $firstname; public function __construct() { parent::__construct(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Get name * * @return string */ public function getName() { return $this->name; } /** * Set name * * @param string $name * @return Utilisateurs */ public function setName($name) { $this->name = $name; return $this; } /** * Get firstname * * @return string */ public function getFirstName() { return $this->firstname; } /** * Set firstname * * @param string $firstname * @return Utilisateurs */ public function setFirstName($firstname) { $this->firstname = $firstname; return $this; } /** * Set photo * * @param \Utilisateurs\UtilisateursBundle\Entity\Photo $photo * @return Utilisateurs */ public function setPhoto(\Utilisateurs\UtilisateursBundle\Entity\Photo $photo) { $this->photo = $photo; return $this; } /** * Get photo * * @return \Utilisateurs\UtilisateursBundle\Entity\Photo */ public function getPhoto() { return $this->photo; } /** * Set firstname * * @param string $firstname * @return Utilisateurs */ }
app\config\config.yml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 <?php namespace Utilisateurs\UtilisateursBundle\Form\Type; use Symfony\Component\Form\FormBuilderInterface; use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType; class RegistrationFormType extends BaseType { public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $builder ->add('name','text',array('label' => 'nom')) ->add('firstname','text',array('label' => 'prenom')); } public function getName() { return 'pv_user_registration'; } }
=> dans ce cas j'ai rajouter les champs nom(name) et prenom(firstname) lors de l'inscription d'utilisateurs mis comment je peux rajouter le champs photo sachant qui n'est pas un champs simple ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 fos_user: db_driver: orm firewall_name: main user_class: Utilisateurs\UtilisateursBundle\Entity\Utilisateurs registration: form: type: pv_user_registration services: pv_user.registration.form.type: class: Utilisateurs\UtilisateursBundle\Form\Type\RegistrationFormType arguments: [%fos_user.model.user.class%] tags: - { name: form.type, alias: pv_user_registration }
et est ce que je peux remplir le table Utilisateurs et Photo dans la même formulaire comme suit:
svp quelqu'un m'aide![]()
Partager