Hy,

I was thinking of 2 naming strategies :

1) You are storing the name of the file in the db
here the current solution is perfect, you get the file name with getValue() ready to be saved in the db

2) You are NOT storing the name of the file in the db and named it base on the primary key value lets say you have this naming scheme : pkValue__photo (1__photo1, 1__photo2, ..., 56__photo1, 56__photo2)
so you call getValue() have the file stored
insert the data in the db, fetch the pk value with lastInsertedId()
and then reapply  the  Rename filter

There is one big difference which is the problem in your assumption.
getValue does NOT return the filename it receives the file and makes several other data in background. The filename is not the value of the file element.

So the logical way in my opinion would be to call getFileName, change the name according to the primary key of the database by applying the rename filter, and then, as last step calling getValues().
If validation or anything other fails, revert db entry.
You could even validate before attaching the rename filter because validation does not receive the file.

if ($file->isValid()) {
   $file->getFileName();
   get id, rework filename
   $file->addFilter('rename', $newfilename);
         ->getValues();
}

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

Reply via email to