A
A
Alexander Panshin2014-03-24 18:57:57
symfony
Alexander Panshin, 2014-03-24 18:57:57

How to properly organize file saving in Doctrine entities?

Let's say we have a news entity with standard news fields: title, publication date, text, "picture to draw attention". Here is about the last point and the question.
I read the recommendations from here: symfony.com/doc/current/cookbook/doctrine/file_upl... My hair stood on end for the following reasons:
1. It turns out that "News" knows too much about implementation details. News absolutely no need to know the details about the file system.
2. Write this sausage every time I need to upload files?
But, apparently, the authors meant that their Document entity is intended only for storing a . After some thought, I came up with the following scenarios:
1. Select pictures into a separate entity "Picture" and attach it one-by-one to News.
2. Write your own Image class and store objects of this class inside News in a serialized form.
Actually, the question is: Is there a third way that I don't see? In general, are there any best practices in this regard?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
r_tretyakov, 2014-03-25
@Enlightened

Look towards SonataMediaBundle .

V
voidMan, 2014-05-04
@voidMan

you can also take a closer look at https://github.com/vitiko/IphpFileStoreBundle , we use . You don’t need to write anything extra, specify the desired type in the annotations. There is integration with Sonata admin.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question