Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc361fe

Browse files
juanmfweaverryan
authored andcommitted
Update file_uploads.rst
Updated as per@RyanWeaver's suggestions.
1 parent2030b28 commitcc361fe

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

‎cookbook/doctrine/file_uploads.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,6 @@ Next, refactor the ``Document`` class to take advantage of these callbacks::
371371
// do whatever you want to generate a unique name
372372
$filename = sha1(uniqid(mt_rand(), true));
373373
$this->path = $filename.'.'.$this->getFile()->guessExtension();
374-
// Note: is you choose to use EvensubScribers, this change has no effect un database Update
375-
// the 'initial' value set in {@link self::setFile()} is used instead. As this occurs
376-
// inside EntityManager#flush() and changeSets are not tracked.
377-
// use \Doctrine\Common\Persistence\Event\PreUpdateEventArgs $args as the handler fn param and
378-
// $args->setNewValue('path', $filename);
379-
// source: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#preupdate
380374
}
381375
}
382376

@@ -416,6 +410,16 @@ Next, refactor the ``Document`` class to take advantage of these callbacks::
416410
}
417411
}
418412

413+
..caution::
414+
415+
When using Doctrine EvensubScribers' preUpdate(\Doctrine\Common\Persistence\Event\PreUpdateEventArgs $args)
416+
callback instead of lifecycle callbacks you also need to invoke, ``$args->setNewValue('path', $filename);``
417+
as at this point changeSets are not updated and the ``path`` change just made won't have effect
418+
in the data base record.
419+
For full reference on preUpdate event restrictions, see `preUpdate`_ in the in the Doctrine Events documentation.
420+
421+
.. _`preUpdate`:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#preupdate
422+
419423
The class now does everything you need: it generates a unique filename before
420424
persisting, moves the file after persisting, and removes the file if the
421425
entity is ever deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp