Skip to content

doctrine file upload example uses dir -- caution added #3419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cookbook/doctrine/file_uploads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ object, which is what's returned after a ``file`` field is submitted::
Using Lifecycle Callbacks
-------------------------

.. caution::

Using lifecycle callbacks is a limited technique that has some drawbacks.
If you want to remove the hard coded ``__DIR__`` reference inside
the ``Document::getUploadRootDir()`` method, the best way is to start
using explicit :doc:`doctrine listeners </cookbook/doctrine/event_listeners_subscribers>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would terminate this sentence at the end of this line. Then you can continue on the following line with "There you will be able [...]"

where you will be able to inject kernel parameters such as
``kernel.root_dir`` to be able to build absolute paths.

Even if this implementation works, it suffers from a major flaw: What if there
is a problem when the entity is persisted? The file would have already moved
to its final location even though the entity's ``path`` property didn't
Expand Down