Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7817721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:19:42+00:00 2026-06-02T06:19:42+00:00

Using doctrine 2.1 (and zend framework 1.11, not that it matters for this matter),

  • 0

Using doctrine 2.1 (and zend framework 1.11, not that it matters for this matter), how can I do post persist and post update actions, that involves re-saving to the db?

For example, creating a unique token based on the just generated primary key’ id, or generating a thumbnail for an uploaded image (which actually doesn’t require re-saving to the db, but still) ?


EDIT – let’s explain, shall we ?

The above is actually a question regarding two scenarios. Both scenarios relate to the following state:

Let’s say I have a User entity. When the object is flushed after it has been marked to be persisted, it’ll have the normal auto-generated id of mysql – meaning running numbers normally beginning at 1, 2, 3, etc..
Each user can upload an image – which he will be able to use in the application – which will have a record in the db as well. So I have another entity called Image. Each Image entity also has an auto-generated id – same methodology as the user id.

Now – here is the scenarios:

  1. When a user uploads an image, I want to generate a thumbnail for that image right after it is saved to the db. This should happen for every new or updated image.
    Since we’re trying to stay smart, I don’t want the code to generate the thumbnail to be written like this:

    $image = new Image();
    …
    $entityManager->persist($image);
    $entityManager->flush();
    callToFunctionThatGeneratesThumbnailOnImage($image);

    but rather I want it to occur automatically on the persisting of the object (well, flush of the persisted object), like the prePersist or preUpdate methods.

  2. Since the user uploaded an image, he get’s a link to it. It will probably look something like: http://www.mysite.com/showImage?id=[IMAGEID].
    This allows anyone to just change the imageid in this link, and see other user’s images.
    So in order to prevent such a thing, I want to generate a unique token for every image. Since it doesn’t really need to be sophisticated, I thought about using the md5 value of the image id, with some salt.
    But for that, I need to have the id of that image – which I’ll only have after flushing the persisted object – then generate the md5, and then saving it again to the db.

Understand that the links for the images are supposed to be publicly accessible so I can’t just allow an authenticated user to view them by some kind of permission rules.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:19:45+00:00Added an answer on June 2, 2026 at 6:19 am

    In the end, I listened to @Arms who commented on the question.
    I started using a service layer for doing such things.
    So now, I have a method in the service layer which creates the Image entity. After it calls the persist and flush, it calls the method that generates the thumbnail.

    The Service Layer pattern is a good solution for such things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working with Zend Framework (using Doctrine as the ORM) for quite a
When creating an association using Doctrine 2 and the Zend Framework, if the associated
I'm using Doctrine with Zend Framework. For my model, I'm using a base class,
I'm using Zend Framework with Doctrine. I'm creating an object, editing, then saving it.
I am using Doctrine 1.2 under the Zend framework to run my database queries.
I'm using Doctrine 2 in a Zend Framework application and require functionality similar to
I am using Doctrine 2 and Zend Framework 1.11. I have set up my
I'm using Zend Framework and doctrine 1.2.x Is there a way to define index-table
i m referring tutorial http://www.webpixel.gr/blog/zend-framework/integrate-doctrine-2-0-1-with-zend-framework-1-11-x and i m using ZendFramework-1.11.11 and doctrine2-2.2.0-BETA2 there is
I'm currently developing a Zend Framework project, using Doctrine as ORM. I ran into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.