see my comments below

Thomas Weidner a écrit :
When you are calling getValue or receive you are saying "please move the file". It would be nonsense to add a behaviour which does NOT move the file when you want to move the file.
Well I found it confusing the first time.

For me if I'm calling getValue I'm not expecting to have my data saved in a directory nor in the database. With getValue I'm expecting just data and then see if I want to save them on not. If so I'm doing a insert/update on the database and call receive to save the file. We could argue that if we call getValue, we are requesting data and with files data are the files them self ...

All this is very subjective, and I can switch my brain logic to work this way. A note in the manual about it could be good.


With the ZF you need the same amount of lines, 3,  as with your solution.
I don't see that this should be more complicated to call isUploaded than to fetch an exception.

if (!$form->file->receive() or !$form->file->isUploaded()) {
   rollback translation
}
you are right.

Btw: Your code does NOT change the name which means that is not representative. Therefor I did also compress my example to show the same behaviour as yours.
Now that I have a better understanding on how Zend_File_Transert all work with Zend_Form and how Zend_Filter_File_Remane work I'm find with all that.
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

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

----- Original Message ----- From: "Laurent Melmoux" <[EMAIL PROTECTED]>
To: "Thomas Weidner" <[EMAIL PROTECTED]>
Cc: "Zend Framework General" <[email protected]>
Sent: Thursday, December 04, 2008 10:07 AM
Subject: Re: [fw-general] [Zend_Form] Zend_Form_Element_File::getValue() is calling Zend_File_Transfer_Http:: receive()


Thomas,

And what about a flag to switch off this behavior ?
I think leaving the developer decide when the save the files fit in the philosophy of the Zend Framework, in term of flexibility.

I agree there is several tricks to go around this but it make my code more complicated :(

Thomas Weidner a écrit :
Laurent,

I would say that the isReceived method is a really easy way to check this. Or you can get the file infos and check for the isReceived tag manually.

You can delete all files which have been received until then without problems.

Changing the name can also easily be done by using the rename filter.

When you want to do the retrievment manually you can do this already with the existing implementation.
Simply use the old syntax instead of the new getValue syntax.
isValid -> rename -> receive

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

----- Original Message ----- From: "Laurent Melmoux" <[EMAIL PROTECTED]>
To: "Zend Framework General" <[email protected]>
Sent: Wednesday, December 03, 2008 7:04 PM
Subject: [fw-general] [Zend_Form] Zend_Form_Element_File::getValue() is calling Zend_File_Transfer_Http:: receive()


Hi,

I’m wondering if it is a good idea to move the uploaded file on Zend_Form_Element_File::getValue() call.

Because:

• If the receive() failed for what ever reason I may not want to go further like inserting the other data in the database. And Currently there is no easy way to check if receive() succeed.
• Or if a database transaction failed I will have to delete the files
• What if we want to name the file from the UID of the database record


Personally I prefer to use this pattern:

$this->db->beginTransaction();
try {

// will not call receive()
$data = $this->form->getValues(); $this->insert($data);
// will call Zend_File_Transfer_Http:: receive()
// if receive() failed throw an exception then no data is inserted
$this->saveFiles();
$this->db->commit();
} catch (Exception $ex) {
$this->db->rollBack();
}

Not calling receive() on Zend_Form_Element_File::getValue() would leave more flexibility for the developer on how he want to handle the file. What do you think?

--
Laurent Melmoux
Conseil et Solutions Web | [EMAIL PROTECTED]
2mx - Annecy, France     | http://laurent.2mx.fr/


Reply via email to