Bonjour,
J'ai deux entités suivantes liées par une relation ManyToOne.

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
127
128
129
130
131
132
133
134
135
// ENTITE Commande
 
* @ORM\Entity(repositoryClass="Env\MonBundle\Repository\CommandeRepository")
* @ORM\Table(name="commande")
*/
 
class Commande
{    
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     * @var integer $id
     */
 
    private $id;
 
    /**
     * @ORM\Column(type="string", length="255")
     * @Assert\NotBlank()
     */
    private $libelle;
 
 
    /**
     * @ORM\ManyToOne(targetEntity="Document",  inversedBy="salle", cascade={"persist"})
     * @ORM\JoinColumn(name="document_ref", referencedColumnName="id")
     * @var Document $document_ref
    */
    public $document_ref;
 
       ........
 
    /**
     * Set document_ref
     *
     * @param Env\MonBundle\Entity\Document $documentRef
     */
   public function setDocumentRef(\Env\MonBundle\Entity\Document $documentRef)
    {
        $this->document_ref = $documentRef;
    }
}	
 
// ENTITE DOCUMENT
 
/**
 * @ORM\Entity
 * @ORM\Table(name="document")
 */
class Document
{    
    /**
     * @ORM\GeneratedValue
     * @ORM\Id
     * @ORM\Column(type="integer")
     * 
	   * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
	  /**
     * @ORM\Column(type="string", length="255")
     * @Assert\NotBlank()
     */
    private $nom;
 
 
    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    public $path;
 
    /**
     * @Assert\File(maxSize="6000000")
     */
    public $file;
 
  	/**
     * @ORM\OneToMany(targetEntity="Commande", mappedBy="document_ref")
     *
     * @var ArrayCollection $commande
     */
    protected $commande;
 
 
    public function getAbsolutePath()
    {
        return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path;
    }
 
    public function getWebPath()
    {
        return null === $this->path ? null : $this->getUploadDir().'/'.$this->path;
    }
 
    protected function getUploadRootDir()
    {
        // the absolute directory path where uploaded documents should be saved
        return __DIR__.'/../../../../web/'.$this->getUploadDir();
    }
 
    protected function getUploadDir()
    {
        // get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
        return 'uploads/documents';
    }
 
    public function upload()
    {
    // the file property can be empty if the field is not required
    if (null === $this->file) {
        return;
    }
 
    // we use the original file name here but you should
    // sanitize it at least to avoid any security issues
 
    // move takes the target directory and then the target filename to move to
    $this->file->move($this->getUploadRootDir(), $this->file->getClientOriginalName());
 
    // set the path property to the filename where you'ved saved the file
    $this->path = $this->file->getClientOriginalName();
 
    // clean up the file property as you won't need it anymore
    $this->file = null;
    }
 
    public function getFilePath()
    {
 
      return  $this->file->getClientOriginalName();
    }
}
Pour ajouter une nouvelle commande voici ce je fais dans mon Controller
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 ......
  if($request->getMethod() == 'POST') {
            $form->bindRequest($request);
            if($form->isValid()) {  		            
               $document->upload(); 
               $em->persist($commande);
               $em->flush();                                                            
            }               
    ..........
Ici l'action est executé jusqu'à la fin, mais au niveau de la table document, le champ path reste toujours vide et j'avais fourni le chemin au niveau du formulaire.
Je demande si quelqu'un aurait une idée.
Merci d'avance