开发者

Symfony problem when need to save file before saving an Entity

I have an Entity on Symfony that has also a file "attached" to it.

I want to save the file with the id of the created Entity.

The problem is, that I will know the Entity's ID only after doing "dosave()" on that Entity form.

Is there any 开发者_C百科way to save the file after doing the "dosave()" but still write the code as an override for the Entity's form code?


Assuming you are using symfony's bundled file widget, then you can't do this, because of the way the form save process works. In short, the file is saved by the validator, but by the nature of it being a validator, the data hasn't been saved yet!

I've worked around this before by using a temporary filename for the file if the object is new, and then after save has completed (but still within an overload in the form class), move it to the real location now that you know the id.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜