Skip to content

Commit e02292c

Browse files
author
Hugo Hamon
committed
[cookbook] fixed file uploads with Doctrine samples to upload the file when the object is both persisted and updated. Added a note about PrePersist, PreUpdate, PostPersist and PostUpdate lifecycle callback events.
1 parent 9274dbf commit e02292c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cookbook/doctrine/file_uploads.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ Next, refactor the ``Document`` class to take advantage of these callbacks::
257257
{
258258
/**
259259
* @ORM\PrePersist()
260+
* @ORM\PreUpdate()
260261
*/
261262
public function preUpload()
262263
{
@@ -268,6 +269,7 @@ Next, refactor the ``Document`` class to take advantage of these callbacks::
268269

269270
/**
270271
* @ORM\PostPersist()
272+
* @ORM\PostUpdate()
271273
*/
272274
public function upload()
273275
{
@@ -298,6 +300,13 @@ The class now does everything you need: it generates a unique filename before
298300
persisting, moves the file after persisting, and removes the file if the
299301
entity is ever deleted.
300302

303+
.. note::
304+
305+
The ``@ORM\PrePersist()`` and ``@ORM\PostPersist()`` event callbacks are
306+
triggered before and after the entity is persisted to the database. On the
307+
other hand, the ``@ORM\PreUpdate()`` and ``@ORM\PostUpdate()`` event
308+
callbacks are called when the entity is udpated.
309+
301310
Using the ``id`` as the filename
302311
--------------------------------
303312

@@ -315,6 +324,7 @@ property, instead of the actual filename::
315324
{
316325
/**
317326
* @ORM\PrePersist()
327+
* @ORM\PreUpdate()
318328
*/
319329
public function preUpload()
320330
{
@@ -325,6 +335,7 @@ property, instead of the actual filename::
325335

326336
/**
327337
* @ORM\PostPersist()
338+
* @ORM\PostUpdate()
328339
*/
329340
public function upload()
330341
{

0 commit comments

Comments
 (0)