I've tried this already, but it doens't work, because $objImage->strIMage is containing the result of "CUploadedFile::getInstance($objImage, "strImage[$n]");"
You should do this in beforeSave(). Otherwise, the validation will fail.
If I do so, I'll get an error:
"strImage must not be empty"
It's a bit more complex, because I'm building a BaseModel, which handles multiple image uploads for a model (i.e. "Teaser" gets an additional Model "TeaserImage").
Everything works fine, except the renaming of uploaded files
You can also declare a public member in the model class to store the uploaded file instance. Leave strImage to store file name only. Then you need to validate on that public member instead of strImage.
You can also declare a public member in the model class to store the uploaded file instance. Leave strImage to store file name only. Then you need to validate on that public member instead of strImage.
Yes, I think I've got it working now:
The trick was, that I validated strImage in function "beforeSave", and then in function "afterSave", when I call "$objImage->save(false)" I turned out validaten, because at this point objImage is already valid.
Now I can set strImage (bevor saving the image) like this: