This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Possible error in Doctrine file upload Cookbook page

About symfony tutorials, symfony book and API documentation.

Possible error in Doctrine file upload Cookbook page

by lytithwyn » Sat Feb 04, 2012 5:40 pm

I may be wrong, but it looks like there might be an error on the page in the Cookbook relating to handling file uploads with Doctrine, specifically in the section that demonstrates the use of lifecycle callbacks.

The page shows this postPersist handler with it's comment:
Code: Select all
     * @ORM\PostPersist()
     * @ORM\PostUpdate()
    public function upload()
        if (null === $this->file) {

        // if there is an error when moving the file, an exception will
        // be automatically thrown by move(). This will properly prevent
        // the entity from being persisted to the database on error
        $this->file->move($this->getUploadRootDir(), $this->path);


That comment says that the entity won't be persisted if an exception is thrown by UploadedFile::move. However, this is a snippet from the Doctrine documentation on Lifecycle Callbacks:
postPersist - The postPersist event occurs for an entity after the entity has been made persistent. It will be invoked after the database insert operations. Generated primary key values are available in the postPersist event.

and again:
10.5.5. postUpdate, postRemove, postPersist

The three post events are called inside EntityManager#flush(). Changes in here are not relevant to the persistence in the database, but you can use this events to

This one is cut off for some reason, but you get the idea. It seems that one or the other most be wrong, either the Symfony2 Cookbook or the Doctrine documentation. I realize I could also just be missing something. I'm never really confident about submitting documentation errata since the people who wrote the docs already know more about it than I do. :D~:-D~:grin:
User avatar
Junior Member
Posts: 9
Joined: Fri Aug 26, 2011 3:22 pm