Answer the question
In order to leave comments, you need to log in
How to create a folder with the id of the new entry. Yii2?
Good afternoon. Tell me please.
The problem is that when I create a new post and immediately attach an image, I need to save it all and put this image in the folder with the number (id) of the post.
It turns out that the photo needs to be put in a folder with the name of which does not yet exist. the record has not yet been saved and there is no where to get the id from.
As I believe this should be done either in the model through beforeSave or in the controller through beforeAction. But how to take it and make brains is not enough.
Tell me please. Thank you very much in advance!
Answer the question
In order to leave comments, you need to log in
why do you need a folder with id? Think of another way to generate the path.
in beforeSave you don't have a post id yet. She appears in afterSave. there, if necessary, you can make the necessary manipulations.
as an option - make a presave record, and already attach pictures according to the existing id.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question