2008年11月18日星期二

Re: [fw-mvc] Zend_Form_Element_File value when not uploading

There is only one file adapter because you have only one $_FILES input
array.
Having multiple file adapters would not work. This is mentioned, because the
first would try to receive the files and the second would then throw an
exception because there are no more files to receive.

What you have in those two variables is the same adapter.

And actually you are calling isUploaded on the adapter (which hold all
uploaded files) and not the form element (where this new method does not
exist for now).

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

----- Original Message -----
From: "Goran Juric" <goran.juric@nacional.hr>
To: <fw-mvc@lists.zend.com>
Sent: Tuesday, November 18, 2008 10:33 PM
Subject: Re: [fw-mvc] Zend_Form_Element_File value when not uploading


>
>
>
> Pieter-12 wrote:
>>
>> When submitting a form with this element, without selecting/uploading
>> a document-file will return 'documents' as its value. Is there a
>> particular reason why this is happening? Is there a way to easily
>> circumvent this from happening or should I use the isUploaded()
>> function of the adapter for each file-element?
>>
>
> I am using something like this:
>
> $adapter = $form->getElement('doc')->getTransferAdapter();
>
> if ($adapter->isUploaded('doc') {
> ...
> }
>
> if ($adapter->isUploaded('employee_cv_file') {
> ...
> }
>
> And it works, but some things still bother me.
>
> As far as I can see, both of the file form elements return the same
> adapter
> class. So doing something like this:
>
> Let's say that you have 2 file elements, and on your form you upload only
> the 'doc', and not the other one, you will get this:
>
> $adapter1 = $form->doc->getTransferAdapter();
> $adapter2 = $form->employee_cv_file->getTransferAdapter();
>
> echo $adapter1->isUploaded(); // returns true
> echo $adapter2->isUploaded(); // returns true
>
> but
>
> echo $adapter1->isUploaded('doc'); // returns true
> echo $adapter1->isUploaded('emplyee_cv_file'); // returns false (note that
> we are still using $adapter1)
>
> I find it strange to fetch the adapter from one element, and use this
> adapter for checking two or more elements and having to provide the name
> of
> the element to the isUploaded method.
>
> Maybe it has something to do with the fact that currently we have only one
> transfer adapter, and that the file element can support upload of multiple
> files, but I still can't wrap my hand around it although my code does what
> I
> want it to do, just not in the way I would like it do it :) (It would be
> more natural for me to either fetch the transfer adapter from the form
> itself and that to check the isUploaded() method providing the element
> name,
> or the fetch multiple adapters each from his element and to test if the
> file
> was uploaded without providing the name of the element since the adapter
> is
> fetched from the element itself).
>
> Sorry for the lengthy post, but I would really appreciate some code
> samples
> showing the "proper way" to handle file uploading.
>
> Regards,
>
> Goran Juric
> http://gogs.info/
> --
> View this message in context:
> http://www.nabble.com/Zend_Form_Element_File-value-when-not-uploading-tp20567916p20568684.html
> Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: