@@ -153,100 +153,11 @@ class Product
153
153
}
154
154
` ` `
155
155
156
- Or, with annotations :
157
-
158
- ` ` ` php
159
- <?php
160
-
161
- namespace App\E ntity;
162
-
163
- use Doctrine\O RM\M apping as ORM;
164
- use Symfony\C omponent\H ttpFoundation\F ile\F ile;
165
- use Vich\UploaderB undle\M apping\A nnotation as Vich;
166
-
167
- /**
168
- * @ORM\E ntity
169
- * @Vich\Uploadabl e
170
- */
171
- class Product
172
- {
173
- /**
174
- * @ORM\I d
175
- * @ORM\C olumn()
176
- * @ORM\G eneratedValue(strategy="AUTO")
177
- */
178
- private ?int $id = null;
179
-
180
- // ... other fields
181
-
182
- /**
183
- * NOTE: This is not a mapped field of entity metadata, just a simple property.
184
- *
185
- * @Vich\Uploadabl eField(mapping="products", fileNameProperty="imageName", size="imageSize")
186
- */
187
- private ?File $imageFile;
188
-
189
- /**
190
- * @ORM\C olumn(nullable="true")
191
- */
192
- private ?string $imageName = null;
193
-
194
- /**
195
- * @ORM\C olumn(nullable="true")
196
- */
197
- private ?int $imageSize = null;
198
-
199
- /**
200
- * @ORM\C olumn(nullable="true")
201
- */
202
- private ?\D ateTimeImmutable $updatedAt = null;
203
-
204
- /**
205
- * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
206
- * of 'UploadedFile' is injected into this setter to trigger the update. If this
207
- * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
208
- * must be able to accept an instance of 'File' as the bundle will inject one here
209
- * during Doctrine hydration.
210
- *
211
- * @param File|\S ymfony\C omponent\H ttpFoundation\F ile\UploadedF ile|null $imageFile
212
- */
213
- public function setImageFile(?File $imageFile = null): void
214
- {
215
- $this->imageFile = $imageFile;
216
-
217
- if (null !== $imageFile) {
218
- // It is required that at least one field changes if you are using doctrine
219
- // otherwise the event listeners won't be called and the file is lost
220
- $this->updatedAt = new \D ateTimeImmutable();
221
- }
222
- }
223
-
224
- public function getImageFile(): ?File
225
- {
226
- return $this->imageFile;
227
- }
228
-
229
- public function setImageName(?string $imageName): void
230
- {
231
- $this->imageName = $imageName;
232
- }
233
-
234
- public function getImageName(): ?string
235
- {
236
- return $this->imageName;
237
- }
238
-
239
- public function setImageSize(?int $imageSize): void
240
- {
241
- $this->imageSize = $imageSize;
242
- }
156
+ **Note:**
243
157
244
- public function getImageSize(): ?int
245
- {
246
- return $this->imageSize;
247
- }
248
- }
249
- ` ` `
158
+ > This bundle also supports annotations, but the attribute syntax is recommended.
159
+ > If you look for examples about annotations mapping, please refer to an older
160
+ > version of the documentation.
250
161
251
162
Alternatively you can use `Vich\UploaderBundle\Entity\File` embeddable for storing file info in your ORM entity :
252
163
0 commit comments