I
I
Ivan Antonov2015-07-27 18:03:11
symfony
Ivan Antonov, 2015-07-27 18:03:11

Return path to uploaded file in doctrine-entity?

Created a File entity with the file upload implementation, as in the official documentation .
How to use the getWebPath method in the DQL query, which I use to display all records on the page?
It used to be like this
CONCAT(photo.folder, photo.filename) filename
, now it needs to be like this

CONCAT('static/', photo.folder, '/', photo.filename) image

I would like to do so . I
photo.webPath image
apologize in advance for not being able to express myself more clearly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-07-27
@antonowano

1) the entity should not be able to upload files.
2) why these perversions in DQL? you can do the same in the getter, or even better, pass a service to the getter that will resolve everything you need through a double dispatch:

function getFile(FileResolver $resolver) {
    // причем только потому что учавствуют два поля
    return $resolver->resolve($this->folder, $this->filename);
}

something like that.
And if we have Doctrine 2.5 we can generally store a value object ala FileReference and then everything is even simpler, then FileReference can be twisted as you like and the same FileResolver could take it as an argument.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question